I’m trying to figure out why one of my Monarch GUI screens is causing an error. It doesn’t happen consistently so it’s difficult to determine. The error stacktrace is as follows:
ERROR:SCRIPT: /monarch/monarch.lua:1042: /monarch/monarch.lua:351: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
[C]: in function 'assert'
/monarch/monarch.lua:1042: in function 'on_message'
/monarch/screen_factory.script:43: in function </monarch/screen_factory.script:35>
Has anyone dealt with this or if @britzl is around maybe you can help me?
EDIT: I disabled popup for the UI element and this reduces the chances but it still happened once in 3 times.
A screen created from a collection factory is somehow broken and has no list of game objects (as returned from collectionfactory.create).
Do you have any errors in the console, perhaps that max instance count was reached? Or it could be that the screen is unloaded twice for some reason…
You can call monarch.debug() at the start of your game. This will make monarch log everything it does. Do you see two calls to unload with no load in between?
Hmm, yes I see that that’s the case (one of my screens unloads twice.) However, I don’t see anywhere that I’m telling it to unload in the path between interacting with the object which opens the UI and when the UI opens. Is there any way to safeguard against this before opening the UI?
EDIT: I solved it thanks to your help! I now call a show on the panel which was unloading twice with clear = true. This forces it to show only 1 of it. Then the other UI panel opens on top of it afterwards. Still can’t find where I’m unloading it twice but this solution works for me.