Pietass Posted June 29, 2015 Share Posted June 29, 2015 Hello i got a problem with destroyElement in table. I can build dynamic objects, but I cant remove object. table = {} i = 1 function createobject (thePlayer, Cname, Aname1, Aname2) if (Aname1 == "create") then local x,y,z = getElementPosition(thePlayer) table[i] = createObject (Aname2, x + 10, y, z + 2, 0, 0, 0) i = i+1 else if (Aname1 == "delete") then table[Aname2] = nil [b]destroyElement (table[Aname2])[/b] else outputChatBox ("ERROR...") end end end addCommandHandler ("o", createobject) -- /o [create/delete] [value] destroyElement don't work Link to comment
MTA Team botder Posted June 30, 2015 MTA Team Share Posted June 30, 2015 table[Aname2] = nil destroyElement (table[Aname2]) You clear the variable before you use it (it will be always nil) Link to comment
Pietass Posted June 30, 2015 Author Share Posted June 30, 2015 function createobject (thePlayer, Cname, Aname1, Aname2) if (Aname1 == "create") then local x,y,z = getElementPosition(thePlayer) table[i] = createObject (Aname2, x + 10, y, z + 2, 0, 0, 0) i = i+1 else if (Aname1 == "delete") then destroyElement (table[Aname2]) (...) It still doesn't work. Link to comment
MTA Team botder Posted June 30, 2015 MTA Team Share Posted June 30, 2015 You should really use (/debugscript 3) to find these mistakes. In line 6 you are using "else if", but it should be "elseif" Link to comment
Ab-47 Posted July 1, 2015 Share Posted July 1, 2015 function createobject (thePlayer, Cname, Aname1, Aname2) if (Aname1 == "create") then local x,y,z = getElementPosition(thePlayer) table[i] = createObject (Aname2, x + 10, y, z + 2, 0, 0, 0) i = i+1 else if (Aname1 == "delete") then destroyElement (table[i]) (...) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now