Castillo Posted March 31, 2012 Posted March 31, 2012 You want to do a for-loop? if so: for i=0, 50 do print ( tostring ( i ) ) end
TopAz Posted March 31, 2012 Author Posted March 31, 2012 And also does the counting of LUA starts from 1?
-ffs-Sniper Posted March 31, 2012 Posted March 31, 2012 With i=0 it starts counting at 0, so it will be executed 51 times.
TopAz Posted March 31, 2012 Author Posted March 31, 2012 With i=0 it starts counting at 0, so it will be executed 51 times. No, I mean on PAWN the positive integer starts from 0 as of the arrays but in LUA it seems otherwise after an experiment on tables. Does it occurs every time that Lua starts counting from 1?
50p Posted April 1, 2012 Posted April 1, 2012 Lua table indices start from 1, although you can still assign value to table[0] but in for loops that use ipairs or pairs, the first index (0) will not be counted, so start your table from 1.
Kenix Posted April 1, 2012 Posted April 1, 2012 t = { [0] = 0; [1] = 1; [2] = 2; } for i, _ in pairs( t ) do print( i ) end --[[ 0 1 2 ]] for i, _ in ipairs( t ) do print( i ) end --[[ 1 2 ]] pairs loop all indexes in table. ipairs loop only number indexes and only in order. t = { [1] = 1; [3] = 3; [4] = 4; } for i, _ in ipairs( t ) do print( i ) end --[[ 1 ]]
TopAz Posted April 1, 2012 Author Posted April 1, 2012 Thank you 50p and Kenix. I'm loving LUA more than PAWN.
MTA Team qaisjp Posted April 2, 2012 MTA Team Posted April 2, 2012 Lua has more understandable code, if not less code required by PRAWN.
TopAz Posted April 2, 2012 Author Posted April 2, 2012 Lua has more understandable code, if not less code required by PRAWN. Yeah, I see.
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