Hi again. When sending messages to all instances of a factory spawned game object, what is the syntax needed for the script from which Im sending the message. Since I have created a table of all the instances but that is in the factory file, and im sending the message(s) from a gui script. Any help would be greatly appreciated!
The factory returns global ids, so you can just iterate over your table with pairs()
to send messages:
for _, id in pairs(your_list_of_instances) do
msg.post(id, message_id, message)
end
To access your table of instances, you can either keep it in a shared module, or send a message to the factory script and relay it in on_message()
.
Thank you : )
Sorry just to clarify, I would send my table of instances from the factory script to my gui script so I can access it and then iterate throug it using pairs() ?
No, I would not send tables of IDs over messages, this can be unsafe. You could either do it like this:
Don’t save the instances locally in your factory script, but save it in a Lua module that is required by both the factory script and the gui script, so you can just send messages from the gui script using that table.
Or like this:
If you want to send a message from your gui script, send it to the factory script, and in the factory send the message you received to the actual receiver.