Jump to content

find button for function


fairyoggy

Recommended Posts

How can I define a button for a function?

function test1()
window1test1 = guiCreateWindow((sW - 419) / 2, (sH - 165) / 2, 280, 310, "test1", false)
local button1 = guiCreateButton ( 5, 25, 120, 25, "btn1", false, window1test1)
addEventHandler("onClientGUIClick",button1,test2,false)
end
addEvent("test1", true)
addEventHandler("test1", root, test1)
addCommandHandler("test1",test1)

function test2()
guiSetEnabled (button1,false)  
end

[Expected gui-element at argument 1, got nil]  

At the moment, I'm getting an error because it can't find the button, how fix?

 

Link to comment
function buttonClick()
  if source == button1 then
    iprint("You clicked me")
  end
addEventHandler("onClientGUIClick", root, buttonClick)
 or 
function buttonClick()
    iprint("You clicked me")
addEventHandler("onClientGUIClick", button1, buttonClick)

 

Edited by Hydra
Link to comment
7 minutes ago, Hydra said:
function buttonClick()
  if source == button1 then
    iprint("You clicked me")
  end
addEventHandler("onClientGUIClick", root, buttonClick)
 or 
function buttonClick()
    iprint("You clicked me")
addEventHandler("onClientGUIClick", button1, buttonClick)

 

you didn’t understand, the button action works, but I need the button to enabled off when pressed, but if I use my code, i have error: "[Expected gui-element at argument 1, got nil]  " in line:
 

guiSetEnabled (button1,false)  

 

Link to comment
1 hour ago, fairyoggy said:

you didn’t understand, the button action works, but I need the button to enabled off when pressed, but if I use my code, i have error: "[Expected gui-element at argument 1, got nil]  " in line:
 

guiSetEnabled (button1,false)  

 

Yea, sorry

Try to do it like this

local button1

function test1()
window1test1 = guiCreateWindow((sW - 419) / 2, (sH - 165) / 2, 280, 310, "test1", false)
button1 = guiCreateButton ( 5, 25, 120, 25, "btn1", false, window1test1)
addEventHandler("onClientGUIClick", root, test2)
end
addEvent("test1", true)
addEventHandler("test1", root, test1)
addCommandHandler("test1",test1)

function test2()
   if source == button1 then
      guiSetEnabled (button1,false)
      removeEventHandler("onClientGUIClick", root, test2)
   end
end

 

  • Like 1
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...