Deleting gameobjects from gui_script

I’m trying to figure out how do I delete a gameobject from my gui_script. Currently, My gui creates game objects via factory.create() and I save the id factory.create returns in a table. I assume I have to use message passing to tell the object to delete itself (msg.post() right?) but how do I get the url from the id I have saved?

Also, is this enough to have a game object delete itself?

function on_message(self, message_id, message, sender)
    go.delete(self)
end

It’s currently the only code on the gameobjects and I don’t have anything else sending my gameobject messages.

Important reminder: When you’re in a .gui_script there is no access to any of the go.* functions and vice versa.

go.delete() will delete the game object the script is attached to. You cannot pass self as in your code snippet.

And you can do a msg.post() to an id returned from factory.create():

local id = factory.create("#factory")
msg.post(id, "foobar")
4 Likes

Thanks, it works perfectly now. You guys have been a BIG help in this project of mine.

3 Likes