Jump to content

Skin changer GUI problem


megaman54

Recommended Posts

Hello! I made this today and i want to know what is wrong with it. It is workin when i type /setskin it loads the GUI all good but when i try to close it via the close button it wont close. So here is the code:

function windowClose()
guiSetvisible(skinGui, false)
guiSetInputEnabled(skinGui, false)
end
addEventHandler ( "onClientGUIClick", closeButton, windowClose, false )

that is only the part of code what closes the gui but it is not working. Tell me what is wrong.

Link to comment

try adding the following after the close button code (change "butttonNameHere" and "functionNameHere" of course):

addEventHandler ( "onClientGUIClick", buttonNameHere, functionNameHere, false, false )

then make a function something like this:

function functionNameHere ()
guiSetVisible ( skinGui, false )
guiSetInputEnabled ( skinGui, false )
end

Link to comment

Another case of learning to debug would prevent a stupid question.

You'll find debugscript reports an error on your addEventHandler line that closeButton is a "bad element pointer". (The message may be different, but the cause is the element doesn't exist.)

As 50p explains, code is executed sequentially when the resource first starts - as this happens, functions are loaded into memory and can then be accessed (why you would normally put a handler line below it's called function) but lines not in functions are executed immediately. (adding the event handler in this case) Functions don't execute until they are called, either by a line outside a function or by event handlers etc.

The assumption here is that you have a function that creates your GUI window - so as the script loads, your createGUI function is loaded and ready to execute, but hasn't been called yet. So your GUI doesn't exist just yet, and any elements created there also don't exist yet and cannot be accessed.

Solution is simple, and there are 2 methods to go about it.

Move your addEventHandler line that attaches to closeButton into the createGUI function AFTER closeButton is created (remember that functions generally get executed after loading the script so your windowClose function is accessible)

or

Don't create your GUI inside a function - it only has to be created once after all, you can hide it (with guiSetVisible) instantly, and then all your GUI elements will be accessible anywhere.

Link to comment
YAY! The close button is working as it should work. But new peoblem is that after i close the window with the button the cursor keeps showing and i can just reconnect to get it off. So do i need to use: guiSetInputEnabled(skinGui, false) or something lese?

It only has one boolean parameter - in this case false. Please learn to use the wiki?

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