Jump to content

How to do this on LUA?


TopAz

Recommended Posts

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?

Link to comment

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.

Link to comment
  
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 
]] 
  

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...