Is there a way to detect in code if the game is launched from the editor via CMD+B or it is running from a bundle?
Not really.
Perhaps if you give us some more context on what you want to do, we can provide a suggestion?
EDIT: Ofc, during bundling, it’s often the case that one uses an extra set of project settings, and you can ofc detect this using sys.get_config()
thanks Mathias!
I am trying to load the fmod audio banks. As suggested here: https://github.com/dapetcu21/defold-fmod they should be put in bundled resources. But in this way I am not able to load them when launching with CMD + B. Perhaps I am missing something…
Yes, fmod is running and eveything worked fine before I tried to load the Banks from bundle resources. It works in a bundle but not via the editor.
@dapetcu21 Hey Marius, could you perhaps help me on this…
EDIT: This is what I am doing
local bundle_path = sys.get_application_path()
local path_to_banks = bundle_path .. "/common/audio/banks"
fmod.studio.system:load_bank_file(path_to_banks .. "/Master Bank.bank", fmod.STUDIO_LOAD_BANK_NORMAL)
fmod.studio.system:load_bank_file(path_to_banks .. "/Master Bank.strings.bank", fmod.STUDIO_LOAD_BANK_NORMAL)
Oh yeah. That’s not gonna work in the editor, since the game is not bundled yet, so bundled resources don’t exist. The way we currently handle this in our games is that we add the banks to custom_resources
, load them from there with load_bank_memory()
when running in editor, and before bundling, our build script removes them from custom_resources
and moves them to bundled resources and the bundled version of the game loads them with load_bank_file()
I see…
But then how you manage this in code? I mean, the code should be different to load from custom_resources with load_bank_memory or from bundled resources via load_bank_file
local system_name = sys_config.system_name
if
env.bundled and not env.banks_from_resources and system_name ~= "HTML5"
then
local bank_path
if system_name == "Darwin" then
bank_path = sys_config.bundle_root_path .. "/Contents/Resources/banks/" .. path
elseif system_name == "Android" then
bank_path = "file:///android_asset/banks/" .. path
else
local sep = sys_config.path_sep
bank_path = sys_config.bundle_root_path
if bank_path:sub(#bank_path) ~= sep then -- If the path doesn't end with a "/", add it (happens on Switch)
bank_path = bank_path .. sep
end
bank_path = bank_path .. "banks" .. sep .. path
end
bank = fmod.studio.system:load_bank_file(bank_path, fmod.STUDIO_LOAD_BANK_NORMAL)
else
local resource = resource.load("/sound/banks/" .. path)
bank = fmod.studio.system:load_bank_memory(resource, fmod.STUDIO_LOAD_BANK_NORMAL)
end
And a few vars for context:
local sys_info = sys.get_sys_info()
sys_config.system_name = sys_info.system_name
sys_config.path_sep = system_name == "Windows" and "\\" or "/"
sys_config.bundle_root_path = sys.get_application_path()
As for how you determine if the game is bundled or not, we use a custom system (env.bundled
), but you could add a property to game.project
or use a --properties
file when calling Bob, since you have to modify game.project
anyway to remove the banks from custom_resources
, then read it with sys.get_config()
.
Thank you so much!
Yes, the config key with a --properties file is a simple solution that should be fine for us!