Jump to content

How to do this on LUA?


TopAz

Recommended Posts

Posted

You want to do a for-loop? if so:

for i=0, 50 do 
     print ( tostring ( i ) ) 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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?

Posted
  
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 
]] 
  

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

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...