Simple Key on, off and on again...!

GuidoGuido Member Posts: 12
edited November -1 in Working with GS (Mac)
Hi, I can not get a simple operation with GS. I want to create
a button-shaped bulb. When the button is not pressed is
off, stays on when pressed. If I press it again
off.

So: button is Off > touch and becomes On.
button is On > touch and becomes Off.

You have solutions on this?

I tried this way but not working as it should:

Rule: "Actor receives event" "touch" is "Pressed"
Change Image: "Set Image to: bulb_on.png

Rule: "Actor receives event" "touch" is "Released"
Change Image: "Set Image to: bulb_off.png

thanks!

Comments

  • StusAppsStusApps Member, PRO Posts: 1,352
    put the bulb_off in the otherwise section under the touch is pressed rule. That'll work
  • GuidoGuido Member Posts: 12
    if you touch the button lights up, but just take off my finger and the button becomes Off , I would rather stay in On position and when I touch again the button becomes Off.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Guido, the following not tested:

    Attribute called onoff.

    When touch is pressed and when self.onoff is true, change attribute to false, change image (to off version).

    When touch is pressed and when self.onoff is false, change attribute to true, change image (to on version).

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • Rob2Rob2 Member Posts: 2,402
    This is a neat alpha toggle method...not images but it shows creative thinking :)

    image
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    When I want to do something like this, I use a counter. Create an attribute on your bulb actor called onOff. Then you'll need two rules:

    First
    When actor receives touch change attribute onOff to (onOff +1)%2. This will cause the value to switch between 0 and 1.

    After that create another rule. When onOff is 0 change image to off.png otherwise change to on.png

    That should work
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    IMO the best way to do this is to use the modulus function which is just the percent sign. Create an integer attribute called self.switch

    Rule
    When touch is pressed
    Change attribute self.switch to (self.switch +1)%2

    New rule when self.switch = 0
    do blah blah
    Otherwise
    Do blah blah blah

    EDIT: didn't read mulcahy's post closely! Like he said :)
  • Rob2Rob2 Member Posts: 2,402
    good one ...even better if you call your images 0.png and 1.png you can do it with just one rule with two change attributes.

    on touch
    self.switch to (self.switch+1)%2
    self.image to self.switch .. self.file (where self.file is a text attribute with .png)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    You dont even need self.file, you can simply put:

    Change Attribute: self.Image to: self.switch..".png"
  • Rob2Rob2 Member Posts: 2,402
    strange...I tried that and it didn't like it first time around...good old GS:)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    scitunes said:
    IMO the best way to do this is to use the modulus function which is just the percent sign.

    Hi scitunes, could you explain the modulus function please?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Check out some of the posts in this thread:

    http://gamesalad.com/forums/topic.php?id=86#post-328

    good luck!
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Thanks! :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • GuidoGuido Member Posts: 12
    Thanks guys ;-)
Sign In or Register to comment.