[SOLVED][1.14.0] - Confused: How To Change Scenes? Have It Perfect Now! Project Provided On Itch

Hi,

New to Defold Engine.
Running version 1.14.0 on Linux x86_64.

What is the correct method to change scenes?
Did some Googling and it seems very complicated?

Savant Savior

Working game demo is on itch site below:

Found below tutorial:

Will try to implement, but don’t understand why scene change is so complicated?

Have something, but it fails on below call to change scene:

msg.post("main:/scene_manager#script", "load_game")

ERROR:GAMEOBJECT: Instance ‘/scene_manager’ could not be found when dispatching message ‘load_game’ sent from main:/go_SceneFade#Scene_Fading

If someone can download the small Defold Engine project on Itch below and provide a fix that would be great!

See top post for URL to game demo on itch!

Looks like that message should be sent to "controller:/scene_manager":

1 Like

Hi,

Thank you for helping…

I tried:
msg.post("controller:/scene_manager", "load_game")
but get below errors:
ERROR:GAMEOBJECT: The collection 'main' could not be created since there is already a socket with the same name.
ERROR:GAMEOBJECT: AcquireResources NewCollection RESULT_OUT_OF_RESOURCES
ERROR:GAMESYS: The collection /main/2-SCN_Defold_Logo.collectionc could not be loaded.
WARNING:RESOURCE: Unable to create resource: /main/2-SCN_Defold_Logo.collectionc: OUT_OF_RESOURCES

This messaging system is new to me.

Savant Savior

1 Like

ERROR:GAMEOBJECT: The collection 'main' could not be created since there is already a socket with the same name

Looks like both your collections are named the same (click on collection and check in Properties)

I can recommend my video about addressing and messagging in Defold:

2 Likes

That fixed the original issue, but there is new issue:
When the second scene is show, it shows both the first scene and second scene?
(please see screenshot below)

1 Like

In the init function of scene manager, it loads the menu/MIT collection directly instead of using your switch_scene function:

function init(self)
	-- Acquire input focus to process scene commands if needed
	msg.post(".", "acquire_input_focus")

	-- Track which proxy URL is currently active
	self.current_scene = nil

	-- Automatically load the main menu on startup
	msg.post("#menu", "load")
end

local function switch_scene(self, new_proxy_url)
	-- If a scene is already running, unload it first
	if self.current_scene then
		msg.post(self.current_scene, "unload")
	end

	-- Set the upcoming target scene
	self.current_scene = new_proxy_url
	msg.post(new_proxy_url, "load")
end

This means that self.current_scene is never set to "#menu" like it should be, and so the menu doesn’t get unloaded later on when the game/logo collection is set to load.

1 Like

Almost there…

There is sometimes a white flicker between scene changes?

I have updated the Itch page with the new source code and Web HTML5 & Linux(x86_64 & Arm64) builds.

See top post for URL to game demo on itch!

Ok, it is perfect now…

URL links above have been updated.

1 Like