How to find attributes of a collided object (SOLVED)

I use a factory which uses a prototype to create different sprites from the atlas it references - done by sending the generated sprite the play_animation message to tell it which sprite to use. I also record the type of sprite by sending the generated sprite a custom message with the sprite_type as payload.

The Lua script used by the prototype does something along the lines of

if (message_id == hash("sprite_type")) then self.spriteType = message.payload end

Now imagine this - the sprites are bumping around in their gameworld and, from time-to-time, they collide. When I trap the collision_response message I know, amongst other things the auto-generated id of the other sprite. But what if I now want to establish the sprite_type of the other sprite prior to deciding how to react.

In other words, how do I find collidedSprite.spriteType?

If the spriteType is a game object property it is possible to access it using go.get():

-- declare the spriteType property at the top of the script file on the objects
go.property("spriteType", hash(""))

-- set it like in your example when you receive the "sprite_type" message
function on_message(self, message_id, message, sender)
    if (message_id == hash("sprite_type")) then self.spriteType = message.payload end
end

In the collision_response handler you construct a URL to the script containing the spriteType property and get it using go.get():


if message_id == hash("collision_response") then
    -- construct a url to the script (I'm assuming the script component has id: scriptid)
    local url = msg.url(nil, message.other_id, "scriptid")
    local spriteType = go.get(url, "spriteType")
end

Thanks