Help with Toggling On/Off

ShaneS429ShaneS429 Member Posts: 77
edited November -1 in Working with GS (Mac)
Currently my game has 3 "abilities" that the player can activate.

Out of the 3 abilities, only 2 can be active at any single time.

I've searched around and found the code to do something along the lines of
(Self.Toggle + 1)%2 which will switch it between 0/1 or off/on.

The problem I am having is allowing only 2 of the 3 abilities to be active at any one time.

If I limit the abilities to only being able to toggle when say ActiveAbilities < 2, this prevents me from turning off the abilities.

I can't seem to figure out a way to have each ability to toggle on/off as long as less than 2 are already active, HOWEVER, still allowing it to toggle off if it is 1 of 2 already active.

Any ideas?

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    well you could have 3 attriutes, one for each ability and have the (self.togle+1)%2 for every attirube, so there would be 3 of those. each time the attirubte is 1 the ability is on and 0 is off.

    then have another attribute called active abilities and have it set to 0.

    then have a rule for each of the abilitiyes, when its attribute is 1 change active abilities to active abilities+1, then another rule when attribute is 0 changeattribute to -1

    then finally in each rule that toggles each ability to 1, have that in a rule thats if active abilitiles is <2

    so each time u turn a ability on it addds one to the active abiltiy attributes and when u turn it off it subtrats one. so if u had 2 on that attribute would be set to 2. and since you can only turn on on when the attributes less then 2, it will only let u have 2 ata atime like you want. and it will still let you turn them off

    there might be a cleaner way to do it, im in class right and now dont really have time at the moment. that should work for u though
  • ShaneS429ShaneS429 Member Posts: 77
    JohnPapiomitis said:
    well you could have 3 attriutes, one for each ability and have the (self.togle+1)%2 for every attirube, so there would be 3 of those. each time the attirubte is 1 the ability is on and 0 is off.

    then have another attribute called active abilities and have it set to 0.

    then have a rule for each of the abilitiyes, when its attribute is 1 change active abilities to active abilities+1, then another rule when attribute is 0 changeattribute to -1

    then finally in each rule that toggles each ability to 1, have that in a rule thats if active abilitiles is <2

    so each time u turn a ability on it addds one to the active abiltiy attributes and when u turn it off it subtrats one. so if u had 2 on that attribute would be set to 2. and since you can only turn on on when the attributes less then 2, it will only let u have 2 ata atime like you want. and it will still let you turn them off

    there might be a cleaner way to do it, im in class right and now dont really have time at the moment. that should work for u though

    Thanks for the response. This is EXACTLY how I have it implemented now BUT the flaw comes with having 2 abilities on.

    If I read your suggestion right, then it will toggle using that formula as long as ActiveAbilities is < 2, meaning 1 or 0.

    But the problem I am running into is say if Ability 1 and Ability 2 are active, then ActiviteAbilities = 2. Since ActiveAbilities is 2, it won't allow anything to toggle, not even the already active ones to let them turn off.

    Stuck on this for about 12 hours now and my head hurts.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934


    this works better than any on/off solution I have ever used
  • ShaneS429ShaneS429 Member Posts: 77
    tenrdrmer said:


    this works better than any on/off solution I have ever used

    Doesn't help at all. I am already doing it that way. My problem is having a set of 3 buttons where only 2 can be active at a time but still allowing active ones to turn off if 2 are already active.
  • crapscraps Member Posts: 353
    Makes sense and work well. I am trying to apply the same methods to have the on / off change scenes. But am having no luck. Is this possible? Ideas?
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    ShaneS429 said:
    Doesn't help at all. I am already doing it that way. My problem is having a set of 3 buttons where only 2 can be active at a time but still allowing active ones to turn off if 2 are already active.

    So you have 3 buttons and you want a max of two buttons on at once? that could be tricky but I think I have an idea to make that work. let me know if thats what you are wanting and I will see if I can make a demo tomorrow.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    what should happen if a user tries to turn on the 3rd button? Should it do nothing or should it turn on and turn off one of the other two?

    would this work?

    create three attributes, one for each button.

    on button one have a rule that says

    `
    if ANY
    button2 is false
    button3 is fales
    change attribute button1 to true
    `
    on button two

    `
    if ANY
    button1 is false
    button3 is fales
    change attribute button2 to true
    `
    and on button three:

    `
    if ANY
    button1 is false
    button2 is fales
    change attribute button3 to true
    `
    that SHOULD allow all buttons to turn on, but requires at least on of the other two to be off already. if they are both true, you won't be able to toggle them.
  • crapscraps Member Posts: 353
    I have a hotspot on a lamp button in a scene. When touched I would like to toggle the lamp off and on using two different images. This is what i set up so far but can not seem to get it working properly.

    Hotspot button
    Rule
    -when touched inside
    -change attribute to game.switchOn to (game.switchOn+1)%2

    Scene image (light off image)
    No rules

    Scene image (light on image)
    Rule
    Interpolate.self.color.alpha = 0
    If game.switchOn = 1
    Interpolate.self.color.alpha =1

    How do I get the light on image to interpolate back to zero when touch again?
Sign In or Register to comment.