Jump to content

Some help with enabling/disabling buttons


Einheit-101

Recommended Posts

Hello Community. I am trying to create some Windows with 3 buttons each and i want to disable a button if a player clicks on it, but the other buttons of this window should be re-enabled so the player is able to choose what he wants. I have 8 Windows like this and i could do the job like this for each window:

function clicked 
if source == Stg then 
    guiSetEnabled ( Stg, false ) 
    guiSetEnabled ( Kar, true) 
    guiSetEnabled ( G43, true) 
elseif source == Kar then 
    guiSetEnabled ( Kar, false ) 
    guiSetEnabled ( Stg, true) 
    guiSetEnabled ( G43, true) 
elseif source == G43 then 
    guiSetEnabled ( G43, false) 
    guiSetEnabled ( Kar, true ) 
    guiSetEnabled ( Stg, true) 
    end 
end 
addEventHandler ( "onClientGUIClick", getRootElement(), clicked ) 

My question is:

Is there a shorter way to script this without writing 100 lines of code for all 8 windows?

Thanks in advance.

Link to comment

You could use a table to store all window and their button.

Like this:

windows = {}

windows.window1 = {}

windows.window1.button1 = ...

Then you use a for loop to find out which button equals the source.

for i, window in ipairs(windows) do

if source == window.button1 then

Link to comment

Would it look like that? This is the Code for my Window and its buttons:

  
whSecondary = guiCreateWindow ( 0.0, 0.329, 0.3, 0.13, "Secondary", true) 
Mp = guiCreateButton ( 0, 0.15, 0.2, 0.25, "MP-40", true, whSecondary ) 
Lug = guiCreateButton ( 0, 0.42, 0.2, 0.25, "Luger P08", true, whSecondary ) 
Sho = guiCreateButton ( 0, 0.69, 0.2, 0.25, "Grabengewehr", true, whSecondary ) 
windows.window1 = {Mp, Lug, Sho} 
  

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