Einheit-101 Posted February 9, 2014 Share Posted February 9, 2014 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
Bonsai Posted February 9, 2014 Share Posted February 9, 2014 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
Einheit-101 Posted February 9, 2014 Author Share Posted February 9, 2014 So i have to put all windows into this table: windows = {} But what data has to be stored in "windows.window1 ={}" ? Link to comment
Bonsai Posted February 9, 2014 Share Posted February 9, 2014 That would be where you create your buttons for each window. Link to comment
Einheit-101 Posted February 9, 2014 Author Share Posted February 9, 2014 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
Bonsai Posted February 9, 2014 Share Posted February 9, 2014 That way you have to use windows.window1[Mp] and so on instead of windows.window1.Mp in your loop. Link to comment
Einheit-101 Posted February 9, 2014 Author Share Posted February 9, 2014 Thank you for your help! I think i can do it now and if not, i will just copy&paste Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now