How to create lists?

I want to store in a list (or something similar) all the gameobjects that trigger with a gameobject and then, send a message to all of them.

example: when a bomb explode, send a message to all the game objects that are inside the explosion area (the explosion area is a collision object of type trigger).

function init (self)
msg.post("#collider", “disable”)
end

local function on_explode (self)
msg.post("#collider", “enable”)
self.targets = {}
end

function on_update (self, dt)
if self.responses_received then
for _,id in ipairs (self.targets)
msg.post ("/"…id, “explosion”)
end
self.responses_received
msg.post ("#collider", “disable”)
end
end

function on_message (self, message_id, message, sender)
if message_id == hash (“collision_response”) then
table.insert (self.targets, message.other_id)
self.responses_received = true
end
end

Was that what you had in mind?

1 Like

yes it was! Thanks!!