On Off Button

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

  • IceboxIcebox Member Posts: 1,485

    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

  • @Icebox said:
    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

  • SocksSocks London, UK.Member Posts: 12,822

    @yoappies02@yahoo.com.sg said:

    Just to confirm:
    Self.on is supposed to be 'true' at the start?

    The starting state doesn't matter.

    @yoappies02@yahoo.com.sg said:
    And when I used your code, I can only turn it off and cannot turn it back on

    Can you show us the rules you are using to switch it on and off, a screenshot would be ideal.

  • yoappies02@yahoo.com.sgyoappies02@yahoo.com.sg Member Posts: 3
    edited May 2016

    @Socks said:

    @yoappies02@yahoo.com.sg said:
    And when I used your code, I can only turn it off and cannot turn it back on

    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

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2016

    @yoappies02@yahoo.com.sg said:
    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

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2016

    // double post

  • nir3112nir3112 Member, PRO Posts: 304

    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.

Sign In or Register to comment.