Jump to content

2 Questions


Karoffe

Recommended Posts

First question is:

for k, player in ipairs(getElementsByType("player")) do 
outputChatBox(getPlayerName(player)) 

in that example it will loop through every player.. how could i make it just loop 1 time and outputs it like that for example "playername1 playername2 playername3"

Second question is:

I remember i saw a loop like that

for index in ipairs(table) do 

what is that used for ?

Link to comment
  • Moderators
local theSupermarket = { 
    "oranges",  -- index 1 
    "apples",   -- index 2 
    "cheese",   -- index 3 
    "pizza",    -- index 4 
} 
  
  
  
for index,content in ipairs(theSupermarket) do  
     
    outputChatBox("The index is: " .. index .. ", the content is: " .. content .. ", bon appetit!") 
end 

Link to comment
  • Moderators

if you want to use "table" which contains all table functions, you need to loop with pairs instead of ipairs. (table doesn't have a array)

  
for index,data in pairs(table) do 
outputChatBox(index .. " " .. tostring(data)) 
end 

remove function: 0x421580 
maxn function: 0x4219a0 
insert function: 0x421800 
concat function: 0x421ac0 
pack function: 0x421900 
unpack function: 0x4216b0 
sort function: 0x4214f0 
  

Will return all table functions + index.

So now you know where the "unpack" function comes from.

value1,value2,value3 = table.unpack(myTable) 
value1,value2,value3 = table["unpack"](myTable) 

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