Jump to content

Getting elements from a GUI


Recommended Posts

Posted

Hi guys,

I'm trying get all elements (gui-widgets) from a Window (like a getElementsByType()). I'm creating this code (resume):

SATHLER_Button["btn_mute"] = guiCreateButton(170, 75, 100, 30, "Mute", false, ModPanelMainWindow) 
SATHLER_Button["btn_kick"] = guiCreateButton(275, 75, 100, 30, "Kick", false, ModPanelMainWindow) 

* Obs: I have many other buttons. It is just a part.

I wanna set the font to all my buttons using:

guiSetFont() 

I'm trying use a loop (in ipairs(), for example) to avoid much work. If I change the "btn_mute" and "btn_kick" (strings) to numbers (1 and 2), can I use:

for i, v in ipairs(SATHLER_Label) do 
        guiSetFont(SATHLER_Button[i], "default-bold-small") 
        guiLabelSetColor(SATHLER_Button[i], 255, 0, 0) 
end 

But I'm not using numbers, I'm using strings to make easier identification. How can I set the font to all elements using a loop? Can I do it? Or to do it I'll use numbers (example: SATHLER_Button[1] and SATHLER_Button[2]) ?

Thanks alot guys,

Stanley Sathler.

Guest Guest4401
Posted

Try that in a for loop.

getElementsByType("gui-button") 

Posted (edited)

try this:

SATHLER_Button = {} 
SATHLER_Button["btn_mute"] = guiCreateButton(170, 75, 100, 30, "Mute", false) 
SATHLER_Button["btn_kick"] = guiCreateButton(275, 75, 100, 30, "Kick", false) 
  
for i, v in pairs(SATHLER_Button) do 
        guiSetFont(v, "default-bold-small") 
end 

I've tested it and it works

Edited by Guest
Posted
SATHLER_Button = { } 
SATHLER_Button [ "btn_mute" ] = guiCreateButton(170, 75, 100, 30, "Mute", false) 
SATHLER_Button [ "btn_kick" ] = guiCreateButton(275, 75, 100, 30, "Kick", false) 
  
for name, button in pairs ( SATHLER_Button ) do 
    guiSetFont ( button, "default-bold-small" ) 
end 

Posted (edited)

Karthik184, in this example don't work. But the information is useful for me, but maybe I'll need it later.

-

Jaysds, working now. I was using "ipairs()", and not "pairs()". Can you say the difference?

-

Solidsnake, thanks you too, man. Thanks all you guys, for the constant help =)

Edited by Guest
Guest Guest4401
Posted
Solidsnake, and what is a "indexed tables"? When I use numbers (e.g: Button[1])?

Yes,

Someone asked the difference between them about it before, and people have given proper explanation too.

Head on : viewtopic.php?f=91&t=42884

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