Ronis Posted January 26, 2016 Share Posted January 26, 2016 Hello, need little help with destroy element, someone can help me what's wrong, why function removeboxfromhands not working function PutBoxOnHand() local pizza = createObject ( 1271, 0, 0, 0 ) exports.bone_attach:attachElementToBone(pizza,source,12,0.081,0.05,0.01,0,-70,0) end addEvent("PutBoxOnHand", true) addEventHandler("PutBoxOnHand", root, PutBoxOnHand) function removeBoxFromHands () if pizza[source] and isElement(pizza[source]) then destroyElement(tank[source]) pizza[source] = nil end end addEvent("removeBoxHands", true) addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands) Link to comment
Noki Posted January 26, 2016 Share Posted January 26, 2016 Use the [/lua] tags next time. pizza = {} function PutBoxOnHand() pizza[source] = createObject ( 1271, 0, 0, 0 ) exports.bone_attach:attachElementToBone(pizza[source],source,12,0.081,0.05,0.01,0,-70,0) end addEvent("PutBoxOnHand", true) addEventHandler("PutBoxOnHand", root, PutBoxOnHand) function removeBoxFromHands () if pizza[source] and isElement(pizza[source]) then destroyElement(pizza[source]) pizza[source] = nil end end addEvent("removeBoxHands", true) addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands) Link to comment
Ronis Posted January 26, 2016 Author Share Posted January 26, 2016 local pizza[source] = createObject ( 1271, 0, 0, 0 ) Here unexpected symbol near '[' Link to comment
tosfera Posted January 26, 2016 Share Posted January 26, 2016 You first have to define pizza as a table before adding it in like that, that's just how lua works; local pizza = { } pizza [ source ] = createObject ( 1271, 0, 0, 0 ) Make sure to put the "local pizza..." at the top of your document to avoid nil values. Link to comment
KariiiM Posted January 26, 2016 Share Posted January 26, 2016 local pizza = {} function PutBoxOnHand() pizza[source] = createObject ( 1271, 0, 0, 0 ) exports.bone_attach:attachElementToBone(pizza[source],source,12,0.081,0.05,0.01,0,-70,0) end addEvent("PutBoxOnHand", true) addEventHandler("PutBoxOnHand", root, PutBoxOnHand) function removeBoxFromHands () if pizza[source] and isElement(pizza[source]) then destroyElement(pizza[source]) pizza[source] = nil end end addEvent("removeBoxHands", true) addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands) Link to comment
Ronis Posted January 26, 2016 Author Share Posted January 26, 2016 Thankyou very very much, it's working very good. And thanks Noki and nosfera Link to comment
Noki Posted January 27, 2016 Share Posted January 27, 2016 local pizza[source] = createObject ( 1271, 0, 0, 0 ) Here unexpected symbol near '[' Look at the code I posted. It does not have a local index declaration. 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