Sasu Posted August 28, 2013 Posted August 28, 2013 I made this function to check if the player is in some colshape in table. function isPlayerWithInZone(source) if source and getElementType(source) == "player" then outputChatBox("TEST1", root) for i,v in ipairs(SXDueloE) do outputChatBox(getElementType(v[1])..", "..getElementType(v[2]), root) if isElementWithinColShape(source, v[2]) then theReturn = true break end end else theReturn = false end return theReturn end And Here when It create the colshape addEventHandler("onResourceStart", resourceRoot, function() for i,v in ipairs(markerPos) do local x,y,z = unpack(v) local marker = createMarker(x, y, z, "cylinder", 2, 255, 0, 0, 100) createBlipAttachedTo(marker, 56) local col = createColSphere(x, y, z, 10) SXDueloE[marker] = {marker, col} end end) My question is why my function return nil? State: Inactive
Moderators IIYAMA Posted August 28, 2013 Moderators Posted August 28, 2013 Line 4: for i,v in pairs(SXDueloE) do That should work reading the table SXDueloE[marker] = {marker, col} Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Sasu Posted August 28, 2013 Author Posted August 28, 2013 I think you didnt understand or I am wrong. I want to check in all the colshapes. State: Inactive
Moderators IIYAMA Posted August 28, 2013 Moderators Posted August 28, 2013 you know ipairs can only check numeric stuff? Why are you trying to use ipairs with a table with markers as key? Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Sasu Posted August 28, 2013 Author Posted August 28, 2013 you know ipairs can only check numeric stuff?Why are you trying to use ipairs with a table with markers as key? Oh, I didnt know that. So, I have to use 'pairs' ? State: Inactive
Moderators IIYAMA Posted August 28, 2013 Moderators Posted August 28, 2013 yes Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Sasu Posted August 28, 2013 Author Posted August 28, 2013 You're right. Thank you very much. State: Inactive
Moderators IIYAMA Posted August 28, 2013 Moderators Posted August 28, 2013 np. BTW:(I don't know if you know this, just as extra info) When you want to check if a table is empty, with keys like that. Use: next(table) local myTable = { ["marker"]=true} if #myTable > 0 then outputChatBox("# is working") -- no it isn't end if next(myTable) then outputChatBox("next is working") -- yes it is end Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Sasu Posted August 28, 2013 Author Posted August 28, 2013 I hope that this will be helpful in the future. Thank you. State: Inactive
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