"Unable to Create Resource" When Specifying a Variable? (SOLVED)

You can see here my error and the problem child. Whenever I specify the caretPos = gui.get_position(etc…), it goes nuts spitting out “Cannot load resource, (etc)” and lists all of my resources because of this one line, saying that it’s a bad argument (I’ve cross-referenced it with my related arguments, which you can see below, and it shows no discrepancies). I take the line out, it’s fine until it gets to the line that calls that variable, but it at least doesn’t say that the resources couldn’t be loaded. Am I doing something incohesive with Defold, or is this a bug?

Move that line 2 lines down into the init function.

The bug is that the error message is really bad. A gui script can read from an associated gui scene (like gui.get_node) only when it has been attached. This happens in the callbacks init, update, etc. The ‘self’ variable can be seen as a part of a gui scene, rather than the gui script. Imagine you were using the Chat.gui_script for both Chat.gui and my_other_scene.gui, then it would not know from which scene to retrieve the “Caret”. When the init/update/on_input runs however, the engine always call them given a specific scene. Does this make sense?

1 Like

I believe so. What you’re saying is that you can’t call upon another source outside the code before initialization has been done? Otherwise it would be calling to code that hasn’t been organized yet, and so couldn’t be found? I will try moving it into the init function, although I tried that before and it didn’t work correctly. I may have written it wrong at that point. Thanks.

1 Like

Yes, exactly! The static initialisation of the script happens once, not once per scene. The init function is however initialisation once per scene.

1 Like