Pressing Buttons Combinations in a Specific Order in GS

Hi everyone,

I am working on a runner game idea where if you get in a certain distance of an enemy, and once you are in that distance, a button combination will pop up on the screen. You have limited time to input this sort of combination (using available buttons) in order to pass that enemy successfully. If you mess up on the order of the button, it resets and you have to do it again. How would I able to pull this off in Gamesalad? If you need any more clearance, let me know!

Example:
an enemy appears. As soon as you are within 100 pixels of it, a combination of buttons will appear BIG on-screen, and you must input that same combination before you run into the enemy. If you did it, the enemy will disappear. If not, then you will run into it and game over.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2013
    Have each button add a value to a sum and then check the sum. So if you have button A worth 1, button B worth 2, and button C worth 4, you can then get 1, 2, 3, 4, 5, 6, or 7 as possible sums for pressing the buttons.

    *Make sure the values are powers of 2 (2^0, 2^1, 2^2, 2^3, etc. = 1, 2, 4, 8, etc.).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • thilanwijthilanwij Member Posts: 20
    Have each button add a value to a sum and then check the sum. So if you have button A worth 1, button B worth 2, and button C worth 4, you can then get 1, 2, 3, 4, 5, 6, or 7 as possible sums for pressing the buttons.

    *Make sure the values are powers of 2 (2^0, 2^1, 2^2, 2^3, etc. = 1, 2, 4, 8, etc.).
    Thanks! But i have another question from that. How would it know immediately if they got the second button press wrong if it checks the sum after the buttons are pressed?
  • thilanwijthilanwij Member Posts: 20
    edited May 2013
    Still having trouble finding out a good logic for the idea :/

    Thinking that tables are a good use for this?
  • thilanwijthilanwij Member Posts: 20
    Tables as you said. Each value stored in a cell. So if button press 1 is not equal to tablecellvalue 1,1 then the user has to start over.
    @uptimistik I was able to do this but something is off with the numbers matching :( I'll keep trying and figure this out!
  • DonaldoukDonaldouk Member, PRO Posts: 63
    Hi thilanwij,

    Im also very interested to know how you get on with that.

    I am a newbie(3months) to gamesalad so are limited to the tool. I am getting the idea of it now. i currently making a game where when the actor is in the air they can execute stunt by a series of commands.

    how was the table method? im trying to work out where to start. lol

    cheers

    Don
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited May 2013
    This is pretty easy Logic. Think logic.

    Create game level integer call Button.total and to put a time frame on the button presses add a REAL game level attribute called ButtonTime

    RULE (1st button in sequense)

    when touch is pressed and game.buttontotal = 0

    Change Attribute Game.ButtonTime to Self.Time

    Change Attribute game.buttontotal to game.buttontotal+1



    OTHERWISE

    Timer after .2sec

    Change Attribute game.button to 0



    New RULE inside (1st Button actor not inside above rule)

    When Attribute Game.Buttontotal (Doesn't = 3) and Self.time > Game.buttonTime+5

    Change Attribute Game.Buttontotal to 0



    RULE (2st button in sequense)

    when touch is pressed and game.buttontotal = 1

    Change Attribute game.buttontotal to game.buttontotal+1

    OTHERWISE

    Timer after .2sec

    Change Attribute game.button to 0



    RULE (3st button in sequense)

    when touch is pressed and game.buttontotal = 2

    Change Attribute game.buttontotal to game.buttontotal+1

    OTHEZRWISE

    Timer after .2sec

    Change Attribute game.button to 0

    Repeat to add more buttons. Easy beans!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    edited May 2013
    I use this method or something similar in Shred Neffland.
    Make a game attribute that is a text attribute for input.
    Make another attribute with the keyword.
    Have a rule that checks if game.keyword begins with the game.input,
    ---When game.keyword is game.input pattern achieved.
    Otherwise (This is if keyword doesn't start with input)
    ---Reset the game.input (Change Attribute game.input to )

    When each button is pressed concatenate the key ID to the game.input
    Change Attribute game.input = game.input..self.ID
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Here's how I'd do it (open the Log Debugger window to see the results).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • DonaldoukDonaldouk Member, PRO Posts: 63
    thanks a lot guys, i will give each a go and see which is better. cheers
  • DonaldoukDonaldouk Member, PRO Posts: 63
    @tatiang i loaded the debugger and preview the code. nothing seem to happen? not a message.

    Am I doing something wrong?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You should see something like this (assuming you pressed A then C then B):

    Log(Actor: button): Correct combo entry… continue
    Log(Actor: button): Correct combo entry… continue
    Log(Actor: button): Wrong combo entry… STOP!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • DonaldoukDonaldouk Member, PRO Posts: 63
    @tatiang I have tried again and its working perfect. Don't why it didn't work yesterday.
    Thanks a lot, its exactly how I want it.

    Cheers
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @Donaldouk You're welcome!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • DonaldoukDonaldouk Member, PRO Posts: 63
    @tatiang Im at the stage of implementing the code for my game. I have encounter few issues and I was wondering if you can show me the light.

    so my problem is,

    I have 4 buttons and 4 combos.

    the patterns are:

    combo A: 1 2 3 4
    combo B: 2 3 4 1
    combo C: 3 4 1 2
    combo D: 4 1 2 3

    so executing the combo with the correct sequence works fine however, when I enter
    1 1 1 1 Combo A also execute. I understand thats because theres a 1 in every col.

    my code is basically same as yours but in the otherwise I have the same rules but searching row 2....then in that otherwise same rules but searching row 3 and same for 4.

    this sounds quite a easy fix but I spent the last 3 hours on it and no luck. :(


  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited June 2013
    Don't use otherwise and let them stand as individual rules. By putting them in otherwise you telling the software if not then do this.
  • DonaldoukDonaldouk Member, PRO Posts: 63
    thanks for the reply @fryingBaconStudio

    I have taken out the otherwise and has them as individual rules, but still no luck.

    Im assuming I need it to read the first input and and see which combo matches and eliminate the one that doesn't.

    will keep trying.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    With the way you want things set up, will probably be much easier to do it the way @CodeMonkey suggests.
  • DonaldoukDonaldouk Member, PRO Posts: 63
    thank you very much RThuman. I will add that to my game as it works out brilliantly. I have spent at least 7 hours trying to figure it out. :((

    but every step is a learning curve. What would i do without this community. =D>

    As being a newbie I must have misunderstood CodeMonkeys method. Thanks @CodeMonkey


    Cheers
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @Donaldouk -- glad it will work for you.

    We all learn from each other. I always look very carefully at @Tatiang's and @CodeMonkey's suggestions. They are always spot on.

    Here is my little mantra:
    When in doubt -- let CodeMonkey spell it out!
  • DonaldoukDonaldouk Member, PRO Posts: 63
    @RThurman

    I have a problem. In your rules for 'Display' you set a timer after 1sec to change input to ""

    Well I added a display text to see the input and it works fine.

    but on mine after 1sec the input display "" before I press any number. I changed the rules to 'change input to (*blank took out the "")' and it seem to work. Will that be a problem?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Its probably OK. Test it out a few times until you are confident its working the way you want.
Sign In or Register to comment.