Jump to content

outputChatBox


Drakath

Recommended Posts

What is more efficient?

This:

for _,v in ipairs(getElementsByType("player")) do 
outputChatBox("Hello",v) 
end 

or this:

outputChatBox("Hello",root) 

This one, I guess:

for _,v in ipairs(getElementsByType("player")) do 
outputChatBox("Hello",v) 
end 

Another one is 30% slower than this one.

Link to comment

as i told you ipairs is for indexed tables, it means every item <<<<>>>> in the table has it's own number: 1 is the index of the first value 2 is the index ot the second's and so on:

local table1 = { 1, 2, 3, 4 } -- First type 
local table2 = { [1] = 1,  [2] = 2, [3] = 3,[4] = 4} -- Second type 
  
  
for i, v in ipairs( table1 ) do --both pairs and ipairs will work in those tables: 
for i, v in pairs( table1 ) do 

but if you have a table like this

local table = { ["Yes"] = 1, [1] = "Table", ["example"] = 2014, [2] = "me", } 
-- ipairs won't work in this case. 

So try to use pairs all the time.

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