0 Favourites

[SOLVED] How do I solve this conditional loop in C2

  • Hello.

    I haven't posted in a while as all the problems I've encountered were easily solved by just taking time and think but this one appears to be a showstopper for me.

    I have a player object that collides with another object. On collision, the players stops for a designated period of time and the gesture control should take place.

    What I need is give a player an ability to make any amount of tries while the player is stopped by previous condition. When time is up, the gesture control goes away and the players starts moving again.

    So what I'm trying to achieve is basically a 2 nested while loops.

    Pseudo code would look like this:

    string gesture = "None";
    while (WaitForSeconds(10))
    {
     
        while (true)
        {
           // Wait for the user to perform a gesture and record it 
            gesture = GetInputGesture();
            if (gesture != "None")
                 break;
        }
       // Do some gesture comparison stuff to increase score
    }
    [/code:6g4mvqsa]
    In addition, this code does contain a problem of a "frozen" gesture. Timed "while" loop could already end, but the nested loop can infinitely wait for the gesture. This is also the problem to solve.
    Is this possible?
  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You just need to remember that C2 is a looping script, similar to being a giant while-loop already. You can use the Timer behaviour to trigger an event when the timer expires, and variables and/or Groups to turn sections of code on or off. Just think how you would do this without the while-loops, as that is guaranteed to not work in C2.

  • Hello. Today I was finally able to produce a working event sheet that is doing exactly what I needed. Thanks for pointing a timer behavior for me.

    Problem is solved.

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