Peace Unto You! Thank you for your response! So to my knowledge I updated my loader script so that it waits now, I’m still new to coding so forgive me if I misunderstand anything. I’ll give my new loader script so you can see if I addressed the issue you brought up, but even with this new script the freezing still happens randomly.
To answer your question, I haven’t been able to re produce it on PC in my defold editor, so today I’ll just leave it running and constantly hit start game to see, but it only happens to my knowledge on my Android phone.
Is there any way to hook my phone up to the debugger?
local function preload_menu(self)
if not self.menu_preloaded then
msg.post("go#menu", "async_load")
print("Preloading Menu in the Background")
end
end
local function load_menu(self)
if self.menu_preloaded then
msg.post("go#menu", "enable") -- Enable directly if preloaded
else
print("Error: Menu not preloaded before load request")
end
end
local function unload_menu(self, callback)
msg.post("go#menu", "disable") -- Disable the menu
msg.post("go#menu", "unload") -- Unload the menu to free memory
self.pending_unload = "menu"
self.unload_callback = callback
end
local function preload_main(self)
if not self.main_game_preloaded then
msg.post("go#main_game", "async_load")
print("Preloading Main Game in the Background")
end
end
local function load_main(self)
if self.main_game_preloaded then
msg.post("go#main_game", "enable") -- Enable directly if preloaded
else
print("Error: Main game not preloaded before load request")
end
end
local function unload_main(self, callback)
msg.post("go#main_game", "disable") -- Disable the main game
msg.post("go#main_game", "unload") -- Unload the main game to free memory
self.pending_unload = "main_game"
self.unload_callback = callback
end
local function preload_main2(self)
if not self.main2_game_preloaded then
msg.post("go#main2_game", "async_load")
print("Preloading Main2 Game in the Background")
end
end
local function load_main2(self)
if self.main2_game_preloaded then
msg.post("go#main2_game", "enable") -- Enable directly if preloaded
else
print("Error: Main2 game not preloaded before load request")
end
end
local function unload_main2(self, callback)
msg.post("go#main2_game", "disable") -- Disable the main2 game
msg.post("go#main2_game", "unload") -- Unload the main2 game to free memory
self.pending_unload = "main2_game"
self.unload_callback = callback
end
function init(self)
msg.post(".", "acquire_input_focus")
-- Preload states
self.menu_preloaded = false
self.main_game_preloaded = false
self.main2_game_preloaded = false
self.pending_unload = nil
self.unload_callback = nil
-- Initial setup
preload_menu(self) -- Preload menu at startup
preload_main(self) -- Preload main game in the background
preload_main2(self) -- Preload main2 game in the background
end
function on_message(self, message_id, message, sender)
if message_id == hash("proxy_loaded") then
if sender == msg.url("go#menu") then
self.menu_preloaded = true
print("Menu preloaded and ready.")
-- Initialize menu after it's preloaded
load_menu(self) -- Explicitly load and enable the menu after it is preloaded
elseif sender == msg.url("go#main_game") then
self.main_game_preloaded = true
print("Main game preloaded and ready.")
elseif sender == msg.url("go#main2_game") then
self.main2_game_preloaded = true
print("Main2 game preloaded and ready.")
end
elseif message_id == hash("proxy_unloaded") then
if self.pending_unload then
print(self.pending_unload .. " unloaded.")
self.pending_unload = nil
if self.unload_callback then
self.unload_callback()
self.unload_callback = nil
end
end
elseif message_id == hash("start_game") then
-- Transition from menu to main game
unload_menu(self, function()
preload_main(self)
load_main(self)
end)
elseif message_id == hash("start_master_mode") then
-- Transition from menu to main2 game (Master Mode)
unload_menu(self, function()
preload_main2(self)
load_main2(self)
end)
elseif message_id == hash("load_menu") then
-- Transition from either game to menu
local function load_menu_callback()
preload_menu(self)
load_menu(self)
end
if self.main_game_preloaded then
unload_main(self, load_menu_callback)
elseif self.main2_game_preloaded then
unload_main2(self, load_menu_callback)
else
load_menu_callback()
end
end
end