Object.Delete()

Discussion about Mods for Prison Architect

Moderator: NBJeff

User avatar
Phraxas
level2
level2
Posts: 107
Joined: Sun Aug 31, 2014 12:10 am
Location: USA - PA

Object.Delete()

Postby Phraxas » Mon Sep 01, 2014 10:28 pm

Has anyone gotten this function to work yet? I don't know how to get it to delete anything as I've tried putting in the type of thing I'm trying to remove, I've tried Object.GetProperty("ObjectName") but of course that property doesn't exist. How the heck do I delete anything if I can't -find- anything by name?
User avatar
knoest26
level5
level5
Posts: 1380
Joined: Thu Jul 11, 2013 6:55 pm
Location: The Netherlands
Contact:

Re: Object.Delete()

Postby knoest26 » Mon Sep 01, 2014 10:52 pm

haven't used it yet but I could imagine it deletes an items you just spawned.
The correct code to spawn/delete something is:

Code: Select all

Object.Spawn("X")                        where X represents the Objects' name
Object.Delete("X")                        where X represents the Objects' name


So you don't need to get the property first. If you don't set a name for the object it should pick the last used object by default (this should be useful to temporarily make something available by linking it to a timer)
User avatar
Phraxas
level2
level2
Posts: 107
Joined: Sun Aug 31, 2014 12:10 am
Location: USA - PA

Re: Object.Delete()

Postby Phraxas » Mon Sep 01, 2014 10:55 pm

Well, I thought that too, but when I put in the string of the object I'm trying to remove, it doesn't throw an error but it doesn't delete it either.

I just want it to delete itself, so if I could just reference "this" like any other conventional means that would be great.
dean.fitz
level0
Posts: 5
Joined: Tue Jan 01, 2013 12:02 am

Re: Object.Delete()

Postby dean.fitz » Wed Sep 03, 2014 2:31 pm

So each time you spawn something, it returns the name, you can use this to delete the spawned object. If you want to delete yourself you need to be a bit more creative. the downside it that it crashes the game. But here is the code anyways.

Code: Select all


function Create()
    local posx = Object.GetProperty("Pos.x")
    local posy = Object.GetProperty("Pos.y")

    local name = Object.Spawn("Tv",posx-2,posy)

    Object.SetProperty("Spawn",name)
    Object.SetProperty("Age",0)
    print() --get the debug window
end


function Update( timePassed )
   
    local age = Object.GetProperty("Age") + timePassed
    local spawn = Object.GetProperty("Spawn");
   
    Object.SetProperty("Age",age)
    if age > 10 and spawn then
        Game.DebugOut("Deleting "..spawn)
        Object.Delete(spawn)
        Object.SetProperty("Spawn",false)
    end
   

    if age > 20 then
        local id = Object.GetProperty("Id.i")
        local uid = Object.GetProperty("Id.u")
        local t = Object.GetProperty("Type")

        name = t.."-"..id.."-"..uid
        _G[name..".i"] = id
        _G[name..".u"] = uid

        --wont get to see this message
        Game.DebugOut("Deleting "..name.."...\n...then crashing :(" )       
        Object.Delete(name)
    end
end

User avatar
Phraxas
level2
level2
Posts: 107
Joined: Sun Aug 31, 2014 12:10 am
Location: USA - PA

Re: Object.Delete()

Postby Phraxas » Wed Sep 03, 2014 5:12 pm

Oh yeah, I figured that out a while ago but forgot to post about the solution. It's not explicitly stated in my tutorial video, but you can see it there..

But thank you for posting the solution for others to see.

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 6 guests