Need a G key command

ZeroRavenZeroRaven Member Posts: 33
edited January 2013 in Working with GS (Mac)
I'm working on a rtype WWII game and I want to have the G key when pressed once, drop the gear or raise the gear.
The Gear animation is a 5 frame animation, and presently only plays when G is held down. And then I cant seem to get the gear to raise unless its just back to frame 1 of animation right then. Any thoughts?

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    You'll need to set an attribute to keep track of the gears state. Something like:

    Make a new Boolean attribute called:
    gearState (set it to false to start with)

    Make a behavior:
    When key G is pressed AND when gearState = false
    Play the drop gear animation AND set gearState to True

    Make another behavior:
    When key G is pressed AND when gearState = True
    Play the raise gear animation AND set gearState to False
  • ZeroRavenZeroRaven Member Posts: 33
    Thanks Jamie I'll check that tonight when I get home. Thanks again!!
  • ZeroRavenZeroRaven Member Posts: 33
    So I have the Key press G, if state is Falso set animation and change to True. Not sure what I did wrong But it wont work properly.
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    I imagine it's just a typo in your post, but if you have your attribute set to "Falso" instead of "False" it won't work properly.
  • ZeroRavenZeroRaven Member Posts: 33
    Yeah that was a typo. Meant False.
    This is how its set up right now:

    Rule: When ALL are happening
    Key: Recieves press "G" is "Down"
    Attribute: if "self.gearstate" is "False"
    Do:
    Animate: Frames set from Gear up o Gear down
    Change Attribute: Set "self.gearstate" to "True"

    and Vice versa for the "Gear up" animation.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi @ZeroRaven I'm not sure why the version @jamie_c gave you isn't working as it should, so perhaps try this other method:

    Rule: When key G is down
    Rule: ---nested in above--- When self.gearstate is false
    Animate gear up to gear down
    Change attribute self.gearstate to true
    Otherwise
    Animate gear down to gear up
    Change attribute self.gearstate to false

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

  • ZeroRavenZeroRaven Member Posts: 33
    @gyroscope

    When you say ~Nested in above~ Do you mean create another Rule INSIDE the rule that exists?
    Or do you mean as I've already set it up, just add the gear up animation in the "else" section.

    Downside seems to be that when G is not being pressed the gear up animation plays and I can only have gear down as long as G is pressed.

    Have I missed a step?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    "Nested in above": yes, the second rule inside the first.

    The "else" section is the same as the Otherwise section...

    Downside seems to be that when G is not being pressed the gear up animation plays and I can only have gear down as long as G is pressed.

    Have I missed a step?
    Ah, I see; OK, if the animation plays even when G is not being pressed, then the rules can't be nested properly.

    But either gear up or down will only work as long as G is pressed with this setup; I didn't realise you wanted differently, sorry.... give me 10 minutes and I'll be back with a solution for you.

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

  • ZeroRavenZeroRaven Member Posts: 33
    Yeah I was hoping to have it toggleable. Thanks to you too gyro
  • LumpAppsLumpApps Member Posts: 2,881
    edited January 2013
    I'd suggest a custom animation instead of the standard GameSalad behavior.
    Then you can stop and reverse the animation whenever you want. I am not at my Mac right now, else I could help you better . :((
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2013

    Hi again @ZeroRaven Sorry for the delay in getting back to you (it was a bit of a long 10 minutes!)....

    I've sorted a way for for each animation to play in full when the G key is pressed (and even when released, as you want); also i've included a timer so that if the G key is pressed during an animation, it won't affect it.

    So hopefully the following will do exactly what you're after now:

    Make a boolean, let's call it Gswitch

    Remake your attribute called gearstate as an integer

    ------------

    Rule: When key G is down AND self.Gswitch is false
    Rule--- nested in above--- When self.gearstate = 0
    Change Attribute self.gearstate to 1
    Otherwise
    Rule: When self.gearstate = 1
    Change Attribute self.gearstate to 2

    -------------

    Rule: When self.gearstate = 1
    Change Attribute self.Gswitch to true
    Animate ---gear up to down
    Timer: After ? seconds ---- length of time of animation
    Change Attribute self.Gswitch to false

    ------------

    Rule: When self.gearstate = 2
    Change Attribute self.Gswitch to true
    Animate ---gear down to up
    Timer: After ? seconds ---- length of time of animation
    Change Attribute self.gearstate to 0

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

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2013

    *bump* thread for @ZeroRaven if solution above still needed...

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

  • ZeroRavenZeroRaven Member Posts: 33
    Ok well I believe I ahve it set up correctly, however when I pres the G key, the gear drop, but then it plays the gear up animation and then wont redo it?
  • ZeroRavenZeroRaven Member Posts: 33
    should have I had marked the "run to completions" or "loops" etc also?
  • DanDaMan123DanDaMan123 Member Posts: 216
    ok I'm not sure if you have it working but what I think you should do is similar to what @jamie_c suggested at first:

    rule: when g is pressed && gearsdown = false, then gearsdown = true
    rule: when g is pressed && gearsdown = true, then gearsdown = false

    Note: it doesn't matter what method you use to toggle the boolean above^^

    rule: if gearsdown = true, then animate gears-going-down
    rule: if gearsdown = false, then animate gears-going-up

    the reason some of the others wouldn't work is because the animation was inside the rule that g must be down, so therefore the animation would only go when g was down. But, by using a separate rule you can avoid the problem, because the boolean gearsdown doesn't revert back after g is lifted
  • ZeroRavenZeroRaven Member Posts: 33
    well @dandaman123 I must admit yours was the simplest idea yet. I dont know if what I want can b achieved in GS. Or if ts just my programming that needs work. Unfortunatly your idea hit the same snag as Jamie and Gyro.

    Animation plays once, and the refuses to accept another toggle even when held down.
    I may need to have the gear lowering conditional to certain points, and not player controlled as I'd hoped.
  • ElfizmElfizm Member Posts: 489
    Mmmm....

    Just a question though and aplogies if it's already mentioned.

    When you press G the gear animates down. And you want that to go all the way down even if G is no longer being pressed.

    Then press G again and it goes all the way pack up with out stoping even if G is not being pressed ??
  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2013
    I've made you a quick demo of another way of doing it (click the landing gear to lower and raise):

    image



    http://www.filedropper.com/landinggear
  • ZeroRavenZeroRaven Member Posts: 33
    Yes @elfizm thats precisely what I was hoping to have.

    And @socks It never occured to me to use a mouse click to toggle gear. Thanks for another thought to it too.
  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2013
    Yes @elfizm thats precisely what I was hoping to have.

    And @socks It never occured to me to use a mouse click to toggle gear. Thanks for another thought to it too.
    Obviously you can change the mouse click for a key press, I was just illustrating the technique of changing a sequence of images not illustrating that you can use a mouse click, change 'touch' to the letter 'G' being pressed - it'll work just the same.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2013
    Ok well I believe I have it set up correctly, however when I pres the G key, the gear drop, but then it plays the gear up animation and then wont redo it?
    It works fine in my test file; maybe you put stuff in the wrong Otherwise section? Anyhow, see below; there's a test file for you to check out if you like..
    should have I had marked the "run to completions" or "loops" etc also?
    You definitely don't want Loop in the Animate behaviours set; but have checked Run to completion in the Timers.

    Hopefully the other guys info or @Socks test file helps you out; still, as a matter of record, here is a test file of my suggestion, with part of an explosion sequence in place of the gears up and down, as an example only:

    To mention again, pressing the G key won't do anything if one of the animation sequences is still playing. As soon as a sequence has played, the G key will trigger the animation again. This flips from one to the other as you want:

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

  • ZeroRavenZeroRaven Member Posts: 33
    Ok @gyroscope I see what I did wrong. the "nested" areas I didnt put under the "do" section. Ok now I see. Thanks for the example project. Helped ALOT!
  • ZeroRavenZeroRaven Member Posts: 33
    Ok @gyroscope so I have it set up as follows

    -----------------------------
    rule:
    key press G
    if game.gear = false

    Do:
    rule:
    if game.newgear = 0

    do:
    change attribute: game.newgear = 1
    --------------------------------

    Rule:
    if game.newgear = 1

    do:
    change attribute: set game.gear = true
    Animate: Gear Down
    Timer: after 1 second (run to completion)
    - Constrain game.gear = false

    ----------------------------------

    Rule:
    if game.newgear = 2

    Do:
    Animate: gear up
    Timer: after 1 second (run to completion)
    - Change atrribute: game.newgear = 0
    ------------------------------------

    Please forgive my shorthand.

    I used the setup from your example as a template more or less. Now the gear down animation plays perfectly. Can these rules be "prototype" specific or must it be "instance" specific?

    Do I need to make a copy of block 1 to handle the game.newgear 1 change to 2?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2013

    They can be either, whichever you prefer, in this case.... I guess you'll want them prototype specific which is fine as no other actor attribiutes are referenced.

    To do this, make the attributes newgear and gear as self attributes (in the prototype in the Inspector, as I'm sure you know) and it should work out fine.

    PS in your shorthand programming above, there seems to be the Otherwise section missing, but I guess that's included in your actual file....

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

  • ZeroRavenZeroRaven Member Posts: 33
    Overlooked that one :(
    Thanks @gyroscope , your a big help.
Sign In or Register to comment.