Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: rickious on Wed 15/04/2015 20:57:02

Title: toggle states on interact [SOLVED]
Post by: rickious on Wed 15/04/2015 20:57:02
So, for example, a light switch.  You click interact and a light turns on (object.Visible = true)  But I want to then click the same switch again for (object.Visible = false). 

I can do this with a workaround, like on clicking the switch (hotspot on room background image) an object appears over the switch and that becomes the next clickable area to make the light invisible and also hide the switch object, revealing the hotspot instead.

But im thinking there is probably a much simpler way.  Let me know as im sure you do  (nod)
Title: Re: toggle states on interact
Post by: ChamberOfFear on Wed 15/04/2015 21:07:37
This is very simple indeed.
gLight.Visible = !gLight.Visible;

Setting a boolean variable to itself with a '!' in front will give the effect of flipping a switch. Since !booleanVariable means the opposite of whatever value that boolean currently holds.
Title: Re: toggle states on interact
Post by: rickious on Wed 15/04/2015 22:28:51
Awesome! knew there would be an easy way but 1 character, that's excellent!  Cheers  (nod)