Jump to content

Setting Color to GUI Labels Table


'LinKin

Recommended Posts

Hello, I've a table like this:

  
g_Window.labels = { 
      label1 = guiCreateLabel(20, 60, 80, 20, "All Teams", false, g_Window.tabPanel.tab1), 
      label2 = guiCreateLabel(20, 50, 30, 20, "Added Teams", false, g_Window.tabPanel.tab1) 
 } 
  

Then I use this function to color them

function toColorLabels() 
    for _, theLabel in ipairs(g_Window.labels) do 
        guiLabelSetColor(theLabel, 226, 172, 42) 
    end 
end 

But it wasn't not working..

Then I changed the for loop to: for _,theLabel in pairs(g_Window.labels) (Notice I changed 'ipairs' to 'pairs')

And then it worked.

What's the difference between ipairs and pairs?

Thanks.

Link to comment

You can use pairs() with any table, but ipairs with indexed-table (=array), that is, where keys are: 1,2,3,4,...

g_Window.labels is a key-value table, because it has keys: "label1", "label2" instead of 1,2; so you need to use pairs in that case.

Why ipairs is even needed? ipairs iterates in the same order as the indexes advance, but pairs doesn't care about order.

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