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.

Software Engineer & Entrepreneur Running Lustrel and VilarikA • Highly engaged on open source community

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

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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 

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

Software Engineer & Entrepreneur Running Lustrel and VilarikA • Highly engaged on open source community

Posted

"ipairs" is used for indexed tables, yours isn't.

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

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

Software Engineer & Entrepreneur Running Lustrel and VilarikA • Highly engaged on open source community

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

Posted

Oh damn, thank you so much for answer, Karthik. I understood perfectly. (:

-

Solidsnake and Jaysds, thanks alot too, homies. You're always helping me here.

Software Engineer & Entrepreneur Running Lustrel and VilarikA • Highly engaged on open source community

Posted

You're welcome :).

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.

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