Monarch not showing screen

Hi everyone, I was wondering if someone familiar with Monarch could help me figure out how to setup a basic menu system. I’ve setup a “main menu” which works fine since I based the structure around the example. However, now I’m trying to add an overlay to the game which has a couple of on-screen buttons. Those buttons I want to pop-up another screen when clicked. I have setup this system like this:

collectionoutline

The main.script initializes the collection by showing the hud screen (which appears fine within the game.) This hud contains two buttons (for now): inventory and stats. I want each of these to pop-up a screen which shows the related information. For now I have started by trying to create the inventory pop-up screen.

In the code for the hud, I have the following:

local node = gui.get_node("inventorybutton")
	if gui.pick_node(node, x, y) then
		msg.post(game_ref, hash("pause"))
		pprint(monarch.dump_stack())
		monarch.show(hash("inventory"))
		pprint("after show inventory")
		pprint(monarch.dump_stack())
	end

This pauses the game using the timescale option and then attempts to show the inventory. I have also tried not pausing the game to see if the timescale was causing the screen to not show up but there’s no difference w/ or w/o it. After I click the inventory button I see the following printout:

DEBUG:SCRIPT: 1 = hash: [menu]
2 = hash: [hud]

DEBUG:SCRIPT: after show inventory
DEBUG:SCRIPT: 1 = hash: [menu]
2 = hash: [hud]

There is no error and the inventory screen I’ve created never runs the init loop or is created (I have another print statement there for testing which never shows up.) I’ve tried a screen_proxy and a screen_factory but there’s no difference. Has anyone seen this or have any ideas of what to check? I have an “about” popup on the main menu setup similarly and it works without issues but for some reason in the overlay portion of the game this screen can not be shown.

I’ve used Monarch extensively but still can’t suggest something without seeing more. It would be helpful to as always to upload a minimal project where it doesn’t work right. Otherwise check the Monarch examples and compare for any possible issues.

1 Like

I’ll see if I can recreate a minimal example if I still can’t figure it out. It’s strange to me that calling show simply does nothing. If I mispell the name of the inventory screen such as “monarch.show(hash(“in3ventory”))” with a 3 inserted in there, I get:

	ERROR:SCRIPT: /monarch/monarch.lua:669: There is no screen registered with id hash: [i3nventory]
	stack traceback:
		[C]: in function 'assert'
		/monarch/monarch.lua:669: in function 'show'
		/uis/ui_overlay/ui_hud.gui_script:110: in function 'activate_pressed_button'
		/uis/ui_overlay/ui_hud.gui_script:131: in function </uis/ui_overlay/ui_hud.gui_script:126>

But if I spell it correctly it silently does nothing and the inventory screen script never internalizes…

There are many things you could such as creating another screen that you want to behave the same and see if it works, then check for differences. Make sure the collectionfactory is pointing to the right place.

I examined the code of monarch.lua in the debugger and it seems like the reason the screen isn’t showing is line 105 of monarch.lua. It seems the queue is “busy” and then the show function returns true, and there’s a comment here which says “-- return true for legacy reasons (before queue existed)”. Not sure wh the queue is busy here, I have similar logic setup for the main menu but it works fine. Is there something I have to do to have multiple monarch menus in the same project?

EDIT: I stepped through the working menu and the popup here shows fine, but the queue isn’t busy for this menu. So it seems this is the main difference. I’ll see if I can figure out how to create a new queue for a separate menu.

Showing a new screen is not instantaneous. There may be transitions (probably not in your case, or did you configure any screen transitions?), collections/factories need to load/unload (unless you have preloaded them) and there may already by an ongoing action (show/hide of a screen).

Monarch should take care of everything for you. The purpose of the queue is to handle a sequence of screens being shown or hidden. You don’t need to create your own queue.

I’d be very happy to look into this if you share the project or create a repro case.

2 Likes

I changed the M.is_busy function to return false always. Now, the inventory pops up but I can’t interact with it. I already removed all transition effects from this menu system prior to this, but it always is saying that active_transition_count is 1. I’m not sure where this endless transition is taking place… I don’t want to leave the code this way since I’m guessing operating on the queue when it’s truly busy would be potentially crash-worthy. Is there a way to stop all active transitions at a certain point?

Monarch is pretty robust but you’ve come up with a way to break it in a way I haven’t heard of before. I’d love to fix this or at least document it. Would it be possible to get my hands on a repro case for this?

3 Likes