Structuring multiple variables

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I found myself facing a hurdle with one of my complex projects which I can't tackle in a good way.

    My problem is: I'm using multiple variables to check if conditions are fulfilled to execute specific actions.

    In this case the player has a "special attack" that is initiated by pressing "s" then "d" and finaly "b", no problem so far. My hurdle comes in that I need another variable to check if any other buttons are pushed so the variable that checks for the special attack input is reseted. This seems to complicate things too much for me, do you have any tips on making it easier to "think in multiple variable steps" or any other way of doing things like these?

  • SDB is the correct sequence

    twistedvoid.com/c3examples/KeySequencing

    Download here:

    twistedvoid.com/c3examples/KeySequencing.c3p

    There's a timer. Each correct key adds 1 to the timer. Every tick the timer is reduced by the delta time. If it reaches 0, the sequence booleans are reset.

    Here's the catch. You can do SDS. In which case, it looks at the second S as if you're restarting the sequence and resets the timer back to 1 second. Anything else is regarded as an invalid sequence.

    Now, for just this one sequence, this will work fine. BUT, if you have a bunch of sequences, you'll need to play with array's.

    And for those who just want to see the code:

    | Global boolean SequenceCorrect1‎ = false
    | Global number Countdown‎ = 0
    | Global boolean SequenceCorrect2‎ = false
    
    + Keyboard: On any key pressed
    ----+ System: Is SequenceCorrect2
    --------+ Keyboard: B is down
    ---------> Text: Set text to "Correct Sequence"
    
    --------+ System: Else
    ---------> System: Set SequenceCorrect1 to False
    ---------> System: Set SequenceCorrect2 to False
    ---------> Text: Set text to "Incorrect Sequence"
    ---------> System: Set Countdown to 0
    
    ----+ System: Is SequenceCorrect1
    ----+ System: [X] Is SequenceCorrect2
    --------+ Keyboard: D is down
    ---------> System: Add 1 to Countdown
    ---------> System: Set SequenceCorrect2 to True
    ---------> Text: Set text to "Sequence 2 Completed"
    
    --------+ System: Else
    ---------> System: Set SequenceCorrect1 to False
    ---------> Text: Set text to "Incorrect Sequence"
    ---------> System: Set Countdown to 0
    
    ----+ System: [X] Is SequenceCorrect1
    ----+ System: [X] Is SequenceCorrect2
    --------+ Keyboard: S is down
    ---------> System: Set SequenceCorrect1 to True
    ---------> System: Set Countdown to 1
    ---------> Text: Set text to "Sequence 1 Completed"
    
    --------+ System: Else
    ---------> System: Set SequenceCorrect1 to False
    ---------> Text: Set text to "Incorrect Sequence"
    ---------> System: Set Countdown to 0
    
    + System: Is SequenceCorrect1
    -> System: Subtract dt from Countdown
    ----+ System: Countdown ≤ 0
    -----> System: Set SequenceCorrect1 to False
    -----> System: Set SequenceCorrect2 to False
    -----> Text: Set text to "Incorrect Sequence"
    
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think this can be done a bit easier, with a single string variable.

    On each key press add this key to the end of the string, and check if the last characters in the string are "SDB". If no keys pressed for 1 second - reset the string to "".

    Here is how I added Doom cheat codes in my game:

  • I think this can be done a bit easier, with a single string variable.

    Yea, but mine is elegant.

    *cough*

  • Ahh, thank you. I understand how this is done now! You helped a lot!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)