Jump to content

help button click loadimage and again click


freudo

Recommended Posts

Hi guys

I write this code:

addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        onoff = guiCreateStaticImage(578, 290, 138, 34, "img/off.png", false)     
    showCursor(true) 
    end 
) 
  
function click() 
    if (source == onoff) then 
        guiStaticImageLoadImage(onoff, "img/on.png") 
    elseif (source == onoff) then 
        guiStaticImageLoadImage(onoff, "img/off.png") 
    end     
end 
addEventHandler("onClientGUIClick",root,click) 
  

I click onoff button and load on button again ı want click and load on button pls help

Link to comment

The first if statement will always be true, it will never run the 2nd one.

You'll have to assign a variable;

local isButtonOn = false; 
  
function click() 
    if (source == onoff and isButtonOn == false) then 
        guiStaticImageLoadImage(onoff, "img/on.png") 
    elseif (source == onoff and isButtonOn == true) then 
        guiStaticImageLoadImage(onoff, "img/off.png") 
    end     
end 
addEventHandler("onClientGUIClick",root,click) 

Link to comment

Just noticed I forgot to update the variable too, my bad;

local isButtonOn = false; 
  
function click() 
    if (source == onoff and isButtonOn == false) then 
        guiStaticImageLoadImage(onoff, "img/on.png") 
        isButtonOn = true 
    elseif (source == onoff and isButtonOn == true) then 
        guiStaticImageLoadImage(onoff, "img/off.png") 
        isButtonOn = false 
    end     
end 
addEventHandler("onClientGUIClick",root,click) 

But maybe you figured it out already :)

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