Sora Posted August 2, 2012 Share Posted August 2, 2012 (edited) hello guys , i created an resource and i created marker and blip in a funiction with global variables and tried to destroy them with another funiction but says bad argument destroyElement(..) .. got nil addEvent("cb",true) addEventHandler("cb",getRootElement(),ct) function ct(player,x,y,z) finishblip = createBlip ( x, y, z, 42, 0, 0, 0, 255, 255,1, 99999,player) finishM = createMarker (x,y,z, "checkpoint", 3, 255, 255, 0, 170,player) addEventHandler("onMarkerHit", finishM,destroy) end function destroy(hitElement) -- some not needed codes was here destroyElement(finishblip) destroyElement(finishM) end my question is , why the script (or the funiction) can't get variables and they are global variables Edited August 2, 2012 by Guest Link to comment
_Dark_ Posted August 2, 2012 Share Posted August 2, 2012 (edited) function ct(player,x,y,z) finishblip = createBlip(x, y, z, 42, 0, 0, 0, 255, 255, 1, 99999, player) finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) addEventHandler("onMarkerHit", finishM, destroy) end addEvent("cb",true) addEventHandler("cb", root, ct) function destroy(hitElement) -- some not needed codes was here destroyElement(finishblip) destroyElement(finishM) end Function must be before addEvent/Handler. Edited August 2, 2012 by Guest Link to comment
myonlake Posted August 2, 2012 Share Posted August 2, 2012 Events must have functions, your function wasn't created when the server checked the event, so it didn't work. EDIT: _Dark_ was first, but here's a simple fix. addEvent("cb", true) addEventHandler("cb", root, function(player, x, y, z) finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) finishblip = createBlipAttachedTo(finishM, 42, 0, 0, 0, 255, 255, 1, 99999, player) addEventHandler("onMarkerHit", finishM, destroy) end ) addEvent("cb", true) addEventHandler("cb", root, function(player, x, y, z) finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) finishblip = createBlipAttachedTo(finishM, 42, 0, 0, 0, 255, 255, 1, 99999, player) addEventHandler("onMarkerHit", finishM, destroy) end ) function destroy(hitElement, matchingDimension) if matchingDimension then destroyElement(finishblip) destroyElement(finishM) end end Link to comment
_Dark_ Posted August 2, 2012 Share Posted August 2, 2012 (edited) If problem not solved try this: addEvent("cb", true) addEventHandler("cb", root, function(player, x, y, z) finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) finishblip = createBlipAttachedTo(finishM, 42, 0, 0, 0, 255, 255, 1, 99999, player) outputChatBox(getElementType(finishM), player) outputChatBox(getElementType(finishblip), player) addEventHandler("onMarkerHit", finishM, destroy) end ) function destroy(hitElement, matchingDimension) if matchingDimension then if isElement(finishM) and isElement(finishblip) then destroyElement(finishblip) destroyElement(finishM) else outputDebugString("'finishM' and/or 'finishblip' are not elements, perhaps not created?") end end end This should output in chatbox Marker and Blip. Edited August 2, 2012 by Guest Link to comment
myonlake Posted August 2, 2012 Share Posted August 2, 2012 Are you sure that you called event cb?Try this: addEvent("cb", true) addEventHandler("cb", root, function(player, x, y, z) finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) finishblip = createBlipAttachedTo(finishM, 42, 0, 0, 0, 255, 255, 1, 99999, player) outputChatBox(getElementType(finishM), player) outputChatBox(getElementType(finishblip), player) addEventHandler("onMarkerHit", finishM, destroy) end ) function destroy(hitElement, matchingDimension) if matchingDimension then if isElement(finishM) and isElement(finishblip) then destroyElement(finishblip) destroyElement(finishM) else outputDebugString("'finishM' and/or 'finishblip' are not elements, perhaps not created?") end end end This should output in chatbox Marker and Blip. I am not sora, you can just delete your message because he haven't tried it yet. Link to comment
_Dark_ Posted August 2, 2012 Share Posted August 2, 2012 Oh sorry, I didn't pay attention to the nickname. Link to comment
Sora Posted August 2, 2012 Author Share Posted August 2, 2012 thank you guys , problem solved ^^ 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