ID:1839606
 
How do I make my chat and input boxes so they are toggle to a invis and visible state?

Code:
    chattoggle()
var/chatswitch=1
if(chatswitch==1)
winset(src,"input3","is-visible = false")
winset(src,"output3","is-visible = false")
chatswitch=0
return
if(chatswitch==0)
winset(src,"input3","is-visible = true")
winset(src,"output3","is-visible = true")
chatswitch=1


it starts off visible and when i click the button it turns it off but when i click the button again it wont show back up how do I fix it?

You're setting chatswitch to 1 and then testing to see if it's 1, which will always be true. You need to actually toggle it. The easiest way would be chatswitch = !chatswitch. Of course that means you need to actually keep chatswitch around as a permanent variable of the mob or calculate it via winget().
So do i just change the chatswitch=1 to chatswitch=!chatswitch?
mob/var/chatswitch=1


And remove this line from the code.

var/chatswitch=1


Then it'll work, to have less lines though you can do the following.

mob
var
chatswitch=1
verb
chattoggle()
chatswitch=!chatswitch
if(chatswitch)
winset(src,"input3","is-visible=true")
winset(src,"output3","is-visible=true")
else
winset(src,"input3","is-visible=false")
winset(src,"output3","is-visible=false")
You might be able to also do code like this, you should test it, but I'm not 100% sure it'll work.

mob
var
chatswitch=1
verb
chattoggle()
chatswitch=!chatswitch
winset(src,"input3","is-visible=[chatswitch]")
winset(src,"output3","is-visible=[chatswitch]")


EDIT: I tested this and it only works the way I showed above, using this method doesn't work because it expects true/false where-as chatswitch is 0 or 1. If you have similar things like this it maybe beneficial to do it like below though.

proc
num2boolean(a)
if(a)
return "true"
else
return "false"
mob
var
chatswitch=1
verb
chattoggle()
chatswitch=!chatswitch
winset(src,"input3","is-visible=[num2boolean(chatswitch)]")
winset(src,"output3","is-visible=[num2boolean(chatswitch)]")
Huh. I had thought that boolaean values with the skin really should be accepting 1 or 0. I'll make the appropriate change.
BTW, this is a better option for converting to true/false, since it's inline and therefore quicker:

#define toBool(x) ((x) ? "true" : "false")
#define fromBool(x) ((x) == "true")