GameSalad

keyboard functionality up, down states as aposed to press and release

childerhouseschilderhouses Posts: 5Member, BASIC

Hi All!
I have been playing around with gamesalad a lot over the past couple months and have been loving it!
I am trying to create some functionality for a game character where the character goes into a sneak mode when a key is pressed.
So if you hit say the A key he goes into a sneak stance then when you hit A again he goes back into normal stance.

thing is there doesn't seem to be as much control over keyboard commands compared to touch commands.

I would really like to be able to give a key a toggle on an off state when pressed AND released but the key commands seems to only be when key is up or down. I have notice the touch commands have this. touch commands that give me more options like when touch is pressed or when touch is released.

I would really love to be able to do this with the keyboard. is there a work around someone could point me towards?

Thanks

Comments

  • childerhouseschilderhouses Posts: 5Member, BASIC

    ... so basically i want some functionality that says if key is pressed And released change boolean to true. then if pressed and released again change boolean to false. not just change if up or down.... sorry if the last poast was long winded :|

  • birdboybirdboy Posts: 274Member, PRO
    edited March 1

    You can do that by creating an integer (call it keyboardA for example). Now under the key A is down rule change keyboardA to 1. In the otherwise section of the rule create a second rule that checks if keyboardA is 1 and do your sneaking stuff in there.
    Example attached.

    keyboardA is only there to make sure the sneaking doesn't trigger when the scene starts. You could leave this integer out entirely but then the actor will instantly change his state on scene start and depending on your setup this could be undesirable.

    As a tip: always use integers instead of booleans. You can set them to 0 and 1 to mimic a boolean but if at some point down the line you need more states you can simply set the integer to 2 or 3 or 21938 which makes them so much more powerful. Also booleans seem to cause mayor issues under html5.

  • pHghostpHghost London, UKPosts: 1,904Member

    Keyboard up/down work pretty much exactly like touch pressed/released. You cannot do a rule with button touch both pressed and released. Or, you can, but it will never do anything, because only one state can be true at one time.

    As @Hoodloc recommends, you need an attribute to control this.

    Simplest way is:

    When key: A is: pressed -- Change: game.sneak to: mod(game.sneak+1,2)

    I recommend setting up game.sneak as an index, not boolean. It will give you the exact same functionality. It wail also give you more flexibility if you need it later and most important of all boolean attributes currently have a tendency to misbehave in HTML5 builds, which is crucial, especially if you are publishing for computers and want to host the game online!

    My early projects used to be full of booleans, but nowadays you will have trouble finding a single one!

  • SocksSocks London, UK.Posts: 12,698Member, PRO

    @pHghost said:
    My early projects used to be full of balloons, but nowadays you will have trouble finding a single one!

  • pHghostpHghost London, UKPosts: 1,904Member
    edited March 1

    No kidding.

Sign In or Register to comment.