britzl/monarch

Monarch appears to be reloading popup scene instead of re-using it

greay opened this issue · 1 comments

greay commented

I'm in the middle of refactoring my GUI code, and I'm a bit confused about how Monarch handles re-showing the same screen
the way I have it set up currently, I call monarch.show(hash("dialogue"), nil, beat)
but my dialogue code throws an error:

ERROR:SCRIPT: /richtext/richtext.lua:678: Node used in the wrong scene

it seems like it's reloading the screen, instead of just re-using it? I think? and all of my existing code assumes that the GUI nodes are going to remain loaded

It might take some amount of work to extract a small reproducable sample, but the setup & intention is this:

  1. I call monarch.show(hash("dialogue"), nil, beat) where beat is a small table with a line of dialogue & some other info.
  2. the dialogue window (monarch scene) uses the richtext component to type out the dialogue. It's set up so that if it's already shown, it will reset & reuse everything.
M.reset = function()
	if current_timer ~= nil then
		timer.cancel(current_timer)
	end
	if name_timer ~= nil then
		timer.cancel(name_timer)
	end
	
	if words ~= nil then
		richtext.remove(words) -- commenting out this line prevents (or hides) the error
	end
	current_timer, name_timer, current_string, current_name, words, metrics = nil
end

(by default, it resets every time, but the 1st time it's pretty much a no-op)

  1. repeat until the player has exhausted the dialogue

I've been able to work around it, as noted, by commenting out the part that resets & reuses the richtext nodes.

This is by design. Monarch follows a pattern of always loading and unloading screens, even when the screen in question is already at the top of the stack.