Jump to content

my GUI button dont work


XetaQuake

Recommended Posts

hi, i have starting with scripting :) and i have get it working to make a GUI window.

I am realy happy 8)

but i have a problem with my "PLAY" button, when i click it, the window dont go away.

Here is a snip from the button:

  
exitButton = guiCreateButton( 0.30, 0.75, 0.4, 0.03, "Play", true ) 
  
addEventHandler( "onClientClick", exitButton, exitTheInfoWindow ) 
  
function exitTheInfoWindow() 
    guiSetVisible( joinInfos, false ) 
    showCursor( false ) 
end   
  

can anybody help me?

Link to comment

now i have

  
exitButton = guiCreateButton( 0.30, 0.75, 0.4, 0.03, "Play", true ) 
  
addEventHandler( "onClientGUIClick", exitButton, exitTheInfoWindow ) 
  
function exitTheInfoWindow() 
    guiSetVisible( joinInfos, false ) 
    showCursor( false ) 
end   
  

but the result is the same :/

@Hedning: i already use guiSetVisible

Link to comment
you could try "debugscript 3" - I couldn't see an error from your code. Another idea might be a outputChatBox in

function exitTheInfoWindow()

- so you know whetever it's called AT ALL

good idea, i have tried it first with outputChatBox -> noting came

than i have use debugscript 3, and he says bad argument @ addEventHandler, so the problem is the event.

but i cant find any problems:

addEventHandler( "onClientGUIClick", exitButton, exitTheInfoWindow ) 

Link to comment

@mabako: i have tried

  
exitButton = guiCreateButton( 0.30, 0.75, 0.4, 0.03, "Play", true ) 
  
function exitTheInfoWindow() 
    guiSetVisible( joinInfos, false ) 
    showCursor( false ) 
end 
  
addEventHandler( "onClientGUIClick", exitButton, exitTheInfoWindow ) 
  

noting change ;(

@50p:

can you explain me a little bit more?

Where should I place exactly getRootElement?

Link to comment

ah great to see this topic i got the same/a similar problem and was just about starting a new topic for it^^

First i started to look for something like this in the standart resource and found out that in the stealthmain_client.lua file the eventhandler for onClientGUIClick is placed in the same function where the button is created so i tried the same in my code...

I used this:

vehicles = { 
      "rc_baron", 
      "rc_tiger", 
      "rc_goblin" 
} 
  
function spawn (button, state, absoluteX, absoluteY) 
    outputChatBox ("Clicked") 
end 
  
function guiMenu () 
    showCursor ( true ) 
    Menu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Select your vehicle", true ) 
    OKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, Menu ) 
    guiWindowSetMovable ( Menu, false ) 
    guiWindowSetSizable ( Menu, false ) 
    GridList = guiCreateGridList ( 0, 0.1, 1, 0.9, true, Menu ) 
    guiGridListSetSelectionMode ( GridList, 2 ) 
    guiGridListAddColumn ( GridList, "Vehicles", 0.3 ) 
    for key,vehicleName in pairs(vehicles) do 
            local row = guiGridListAddRow ( GridList ) 
            guiGridListSetItemText ( GridList, row, 1, vehicleName, false, false ) 
      end 
    addEventHandler ("onClientGUIClick", OKButton, spawn) 
end 

But what happened now was really strange. The Button went really dark as if it is placed behind the window and if i clicked on it nothing happened. But if i clicked on the border of the window somehow the function spawn was called... As if the declaration OKButton in the eventhandler also declares the parent elements of the button, the Window.

I hope someone can help xeta and me with this problem =)

Link to comment
ah great to see this topic i got the same/a similar problem and was just about starting a new topic for it^^

First i started to look for something like this in the standart resource and found out that in the stealthmain_client.lua file the eventhandler for onClientGUIClick is placed in the same function where the button is created so i tried the same in my code...

I used this:

vehicles = { 
      "rc_baron", 
      "rc_tiger", 
      "rc_goblin" 
} 
  
function spawn (button, state, absoluteX, absoluteY)    outputChatBox ("Clicked") 
end 
  
function guiMenu () 
    showCursor ( true ) 
    Menu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Select your vehicle", true ) 
    OKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, Menu ) 
    guiWindowSetMovable ( Menu, false ) 
    guiWindowSetSizable ( Menu, false ) 
    GridList = guiCreateGridList ( 0, 0.1, 1, 0.9, true, Menu ) 
    guiGridListSetSelectionMode ( GridList, 2 ) 
    guiGridListAddColumn ( GridList, "Vehicles", 0.3 ) 
    for key,vehicleName in pairs(vehicles) do 
            local row = guiGridListAddRow ( GridList ) 
            guiGridListSetItemText ( GridList, row, 1, vehicleName, false, false ) 
      end 
    addEventHandler ("onClientGUIClick", OKButton, spawn) 
end 

But what happened now was really strange. The Button went really dark as if it is placed behind the window and if i clicked on it nothing happened. But if i clicked on the border of the window somehow the function spawn was called... As if the declaration OKButton in the eventhandler also declares the parent elements of the button, the Window.

I hope someone can help xeta and me with this problem =)

i thank you :D now the cursor go away when i clicked and i have make a outputChatBox ("Clicked") that shows to :D

but,

the window joinInfos dont go away, i think anything like this is not correct:

guiSetVisible ( joinInfos, false ) 

can anybody help?

I have a suspicion: my script need a

guiSetVisible ( joinInfos, true ) 

befor i change it to false, is that possibly?

-----

by the way, eXo|Mr.Hankey i will try to help you:

change

    OKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, Menu ) 

to

    OKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true ) 

Link to comment
can anybody help?

I have a suspicion: my script need a

guiSetVisible ( joinInfos, true ) 

befor i change it to false, is that possibly?

Is this what you want?

You can set it to true whenever you want. When you change it to false it will simply disappear.

I don't actually get your question.

Link to comment

hm... well if i dont make the window the parent it works well but the thing is that if i assign the window as a parent and create the button AFTER all the other gui elements it works also until you click on the gridlist or the window... then the button switches to the background.

So now i just made an event onClientGUIClick for the Window and everytime you click on something in the window it will bring the button back to the front using guiBringToFront (OKButton).

Looks a bit buggy but it works and that's all i wanted =)

Anyway thanks for the help xeta :D

Link to comment

hm.. maybe it's because you use local variables. In the scripting wiki examples it's always something like

joinInfos = guiCreateWindow ( 0.30, 0.25, 0.4, 0.5, "Welcome", true ) 
--instead of 
local joinInfos = guiCreateWindow ( 0.30, 0.25, 0.4, 0.5, "Welcome", true ) 

Another thing is the end you're using at line 24 because. For what is it?! looks like a piece of code you forgot to erase^^

But because i create all those guiElement in a function that is called onPlayerJoin or onResourceStart i dont really know if it works then.

Link to comment

  
exitButton = guiCreateButton( 0.30, 0.75, 0.4, 0.03, "Play", true ) 
  
addEventHandler( "onClientGUIClick", exitButton, exitTheInfoWindow )  
function ( ) 
    if (source == exitButton) then 
    guiSetVisible( joinInfos, false ) 
    showCursor( false ) 
end   
  

you forgot the:

if (source == exitButton) then 

This tells activates the command when someone pushes the "Play" Button.

Greatings Frank

Link to comment

frank you dont have to check if the source is the button because if you set the root element of the eventhandler to the button element the function wont be called if you click for example on another button so it can only be true and the source element will never be another then the button you defined as the root element :D

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