Monarch - Simple screen manager

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

Ah yes, that might be it. If so, it wouldn’t be Monarch causing it specifically, but rather any message.

Searching the forum it looks like the “set_speed” message is used in some Defold tutorials, and maybe in other Defold users’ projects, so it would be strange if this hadn’t been flagged before.

Which Defold version introduced the sound speed parameter?

Ps. If this is indeed the case, is there a list of red flag message IDs that shouldn’t be used for arbitrary messages? I think set_enabled is one?

I put this in a project that doesn’t have Monarch and got the same results as you:

msg.post(".", "set_speed", {kmh = 250})
DEBUG:SCRIPT: hash: [set_speed]
DEBUG:SCRIPT: 
{ --[[0000015544431E90]]
  speed = 1
}

Reserved messages are discussed in this thread, but “set_speed” is not mentioned. Looks like the sound speed parameter was added in 1.2.162, which is after the thread on reserved words happened and might explain the absence from the list. If indeed my theory is correct.

2 Likes

As you mention, searching the entire code base for “set_speed” returns zero results.
Indeed, using “set_pan” give a value of 0, which is the default value of the sound pan property.
So it must be some more generic code path that does this.
I don’t get the same behavior by using e.g. the “tracking” property of a label by using “set_tracking”. We need to debug this to know more.

2 Likes

hi, how to mute monarch logs?

Monarch should be muted by default:

You probably have a call to monarch.debug() somewhere?

1 Like