villr Posted September 20, 2012 Share Posted September 20, 2012 (edited) Hello, how can i define how many objects i get from this code? local objects = 0 addEvent( "seeIfThereisCrates", true ) addEventHandler( "seeIfThereisCrates", getLocalPlayer(), function (player) for i,elem in ipairs(getElementsByType("object")) do if getElementModel(elem) == 2912 then local objects = elem+1 outputChatBox("client:".. objects) Itested that and didnt work It always tell me 1. EDIT: And dont think i didnt use ends and things like that because its not in the code LOL. Edited September 20, 2012 by Guest Link to comment
TAPL Posted September 20, 2012 Share Posted September 20, 2012 addEvent("seeIfThereisCrates", true) addEventHandler("seeIfThereisCrates", root, function (player) local objects = 0 for i,elem in ipairs(getElementsByType("object")) do if getElementModel(elem) == 2912 then local objects = objects + 1 end end outputChatBox("client: "..objects) end) Link to comment
Guest Guest4401 Posted September 20, 2012 Share Posted September 20, 2012 addEvent("seeIfThereisCrates", true) addEventHandler("seeIfThereisCrates", root, function (player) local objects = 0 for i,elem in ipairs(getElementsByType("object")) do if getElementModel(elem) == 2912 then objects = objects + 1 end end outputChatBox("client: "..objects) end ) Link to comment
villr Posted September 20, 2012 Author Share Posted September 20, 2012 addEvent("seeIfThereisCrates", true) addEventHandler("seeIfThereisCrates", root, function (player) local objects = 0 for i,elem in ipairs(getElementsByType("object")) do if getElementModel(elem) == 2912 then objects = objects + 1 end end outputChatBox("client: "..objects) end ) Thanks! Link to comment
TAPL Posted September 20, 2012 Share Posted September 20, 2012 and my code not work? lol Link to comment
Guest Guest4401 Posted September 20, 2012 Share Posted September 20, 2012 and my code not work? lol local o = 0 for i = 1,5 do o = o + 1 end print(o) --> 5 local o = 0 for i = 1,5 do local o = o + 1 end print(o) --> 0 Link to comment
TAPL Posted September 20, 2012 Share Posted September 20, 2012 and my code not work? lol local o = 0 for i = 1,5 do o = o + 1 end print(o) --> 5 local o = 0 for i = 1,5 do local o = o + 1 end print(o) --> 0 really? i have tested my code and it work, all you have did is making it global while this not needed since he will not use it outside the function. Link to comment
Guest Guest4401 Posted September 20, 2012 Share Posted September 20, 2012 all you have did is making it global while this not needed It is needed. 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