Monarch - Simple screen manager

You can use code like in top comment here to create a gui node that you can then animate how you want while you transition

2 Likes

Updated URLs (the top one doesn’t work):


2 Likes

Hi. I saw that this link https://www.defold.com/community/projects/88415/ was broken. If it is possible, can you update link to real project?

Sure thing, here you go: https://defold.com/assets/monarch/

2 Likes

@britzl, Thank you very much.

Hey @britzl, thank you so much for this amazing extension! Pretty sure I’ll use it in all my projects (once I’ll finally make it work).

But for now… I just added Monarch to one of my prototype and set it up just like in the Tweet Fighter example (pretty cool game name by the way :grin:). Only changed a bunch of URLs/paths and names/ids…

But for some reason… it doesn’t work. I thought I got how it worked and it seemed really easy to use, but I must have missed something important and I don’t know what. Maybe you can help :pray:

Here are a few screenshots of the set up:

image
image
image
image


Here is my controller.script (supposed to automatically load the char_selector collection):

local monarch = require "lua-modules.libs-defold.monarch.monarch"

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#", "start")

	self.test = 0
end

function update(self, dt)

end

function on_message(self, message_id, message, sender)
	if message_id == hash("start") then
		monarch.show(hash("char_selector"))
		self.test = self.test + 1
		print("self.test = "..self.test)
	end
end

Result: black screen

and the debug “self.test” variable is endlessly set to 1.
image

No error message, but nothing happens. :thinking::sob:

Is my controller script looping on itself or something? (since the self.test is not incremented beyond 1)
(I really don’t see any differences between my “char_selector” screen and the “title’” screen of the Tweet Fighter project)


PS: probably nothing to do with my issue, but:
image

PPS (edit): nothing to do with my issue, but… in this situation (issue/question related to some old stuff), should I bump the old topic or create a new one? :thinking:

@Ragetto I created a basic example with only two screens and basic navigation:

Please have a look at this example and compare to what you have.

2 Likes

Ok I found the issue (my mistake) after testing with another scene. For some reason, the controller script I was using here was also present in a game object of the char_selector collection (I’ve been lazy/tired enough to recycle an old unused script… definitely not a wise move… will never do that again for sure)

Your basic example is very clear and straightforward, but the Tweet Fighter game was also a perfect illustration of how it works.

Anyway this extension is really useful and easy to use, thanks!

1 Like

I’ve released a new version of Monarch which removes the annoying flicker that can happen when switching screens. The new version of Monarch fully loads the next screen before starting to transition out the old screen.

9 Likes

I’m pretty sure that this new version borked “monarch.top()”
Suddenly my game fails in the init of a screen’s scripts, because “monarch.top()” returns nil.

Oh, really? Can you please describe your setup so that I can try to reproduce it?

This is my controller script:

local monarch = require "monarch.monarch"

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#", "start")
end

function on_message(self, message_id, message, sender)
	if message_id == hash("start") then
		monarch.show(hash("musicSpace"),{no_stack=true})
		--monarch.show(hash("gameSpace"),{no_stack=true})
		
		--monarch.show(hash("Mousechief"))
		--monarch.show(hash("Introduction"))
		--monarch.show(hash("BattleOne"))
		monarch.show(hash("combat"), {}, {"battle01"})
		--monarch.show(hash("testScreen"), {}, {"testScript"})
				
	end 
end


In the script for screen “combat”, the init function, calling monarch.top() returns nil.

1 Like

Excellent. I’ll try to repro and issue a fix.

While you’re working on that, how can I roll back to a previous version?

I tried replacing the dependency with:
https://github.com/britzl/monarch/releases/monarch-3.3.0.zip

but that doesn’t seem to work.

You should be able to pick any version from the release page:

Remember to use Project->Fetch Libraries as well as get the new version!

Hey, I was close. The correct url is:

https://github.com/britzl/monarch/archive/refs/tags/3.3.0.zip

thanks!

1 Like

Just to verify - rolling back did solve the monarch.top() issue.

1 Like

I’ve added a GitHub issue to track the monarch.top() issue: Calling monarch.top() is returning nil · Issue #76 · britzl/monarch · GitHub

2 Likes

I’ve stumbled on a very strange issue I’ve finally tracked down to Monarch.

This message:

monarch.post("hud", "set_speed", {kmh = 256})

Is received as:

DEBUG:SCRIPT: on_message(),
{ --[[0x119740130]]
	speed = 1
}

For some reason the {kmh = 256} is entirely ignored and {speed = 1} is sent instead.

I wouldn’t believe it myself, if I hadn’t managed to create a minimal example which produces the same result!

Monarch set_speed.zip (2.9 KB)

I’m still scratching my head.

My working theory was that the sound speed parameter posted “set_speed” as a message under the hood, but I couldn’t find “set_speed” anywhere in the defold editor repo. Perhaps it’s something along those lines though?

1 Like