Hi, I need to send a table of nodes to another script, I used msg.post and sent the table, but I got
“keys in table must be of type number or string (found userdata)”
How can I do? thanks
Hi, I need to send a table of nodes to another script, I used msg.post and sent the table, but I got
“keys in table must be of type number or string (found userdata)”
How can I do? thanks
What are you going to do with the nodes on the other end? You can only manipulate nodes from the same GUI scene.
change his properties, move them …
I have problems sending tables with functions too. I have a module where I create tables(objects) with properties and functions, I sent this objects as parameters of a message, but they lost all the functions after sending them…
for nodes, the solution may be ,send a message to the gui that owns the nodes, and each message executes a function…
To much problems for interact with the objects in the game, if I cant pass objects or references thought the diferent scripts
The short answer: You can’t.
You need to change how you organize your code. Defold is a bit weird; object oriented techniques that you used in other engines may not be very effective here.
With Defold, you communicate between objects with message passing and addresses, not the objects themselves. Likewise, GUI nodes can be referred to by name (but only by their parent gui script of course). Within a single script you can pass around “object” tables with function properties or whatever you want, but between scripts it’s a real pain. The easiest way would be to make string or hash keys for your “objects”, like Defold’s object addresses.
In my experience it’s best to keep your entire interface in one .gui file, with one .gui_script. Then use lua modules to handle the common features (buttons, etc.) and keep your gui_script’s size manageable. It may seem natural to make each button a .gui object, but that will be much harder and less performant.
If you really want to, you can bypass the message passing system altogether, by passing callback functions around through lua modules, but I think it’s more trouble than it’s worth.
Thanks, the problem was a bad design in the begining of my project, need to use more modules and message pasing.
In modules can I use go functions and gui functions?
Yes, lua
module doesn’t have own context and works in the context of the script that called module function.
oh nice, thanks