On Off Button
yoappies02@yahoo.com.sg
Member Posts: 3
I tried doing an on off button (which is the light bulb), but I do not understand why it is not working.
The file is here:tinyurl.com/zdlp4sm
Comments
Just do this .. create a self boolean call it on
Then create a rule
If touch is pressed change attribute self.on to not(self.on)
Now if self.on is true turn lights on otherwise off
Just to confirm:
Self.on is supposed to be 'true' at the start?
And when I used your code, I can only turn it off and cannot turn it back on
The starting state doesn't matter.
Can you show us the rules you are using to switch it on and off, a screenshot would be ideal.
Here is the file: http://tinyurl.com/jgxwp52
The rules are saying - if the actor is touched then change the image to 10743-2002 (the lit lightbulb) . . . . there is nothing in the rules that changes the lightbulb back to unlit.
Your otherwise section is essentially saying: if 'switch On/Off' is false then change the image to the off image, but there is nothing in your rules that makes the attribute 'switch On/Off' false - and triggers the otherwise section.
. . . . . . . . . . . . . . . .
A simpler way:
Rename your images to 0 and 1 (and reimport them).
Rule: When touch is pressed
--Change self.image to 1-self.image
// double post
You can use integer attribue for it
Make a rule "when touch is pressed"
"Change attribute game.on/off to (game.on/off+1)%2"
Then the integer can be just 1 or 0 (or 1 or 2 im not sure im not home right now..) every time you press on it no metter the first state it was
The say if its 0 light off if 1 light on
Hope it help and corrct I'm not on my computer now.