Object.Delete()
Moderator: NBJeff
Object.Delete()
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?
Re: Object.Delete()
haven't used it yet but I could imagine it deletes an items you just spawned.
The correct code to spawn/delete something is:
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)
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' nameSo 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)
Re: Object.Delete()
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.
I just want it to delete itself, so if I could just reference "this" like any other conventional means that would be great.
Re: Object.Delete()
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
Re: Object.Delete()
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.
But thank you for posting the solution for others to see.
Who is online
Users browsing this forum: No registered users and 6 guests



