A single "While" stops my whole game.

0 favourites
  • 8 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hey.

    I'm using the following conditions all in in the same single event.

    System -> While

    System -> Player.X > 500

    System -> Player.X < 900

    -> Set Scroll to Player.X

    (Player.X starts originally at 700)

    However, when the 'While' is in there, the game started with a black screen(it doesnt work). I remove the While and then it works great. Am I doing something wrong?

  • I haven't gotten the While loop mastered, myself. It is rather tricky to understand.

    Can you detail a bit more what you're trying to do?

    Also, you might want to look into the Stop loop action to break out of the loop, otherwise it will continue and lock up the game as you've noticed.

  • yeah the capx would be helpfull

  • Xionor

    The problem is that you are stuck in an infinite loop within the WHILE. The way WHILE works is that it will continue to loop as long as its conditions are true. You have two conditions. Player.X is between 500 and 900. So if that is true, the game will continue to stay in the WHILE loop and SCROLL to Player.X. So SCROLLING is your only action. But SCROLLING does nothing to change your Player.X. The game can't get input from outside the loop to see that you are pressing the left button and moving Player.X to less than 500. It's stuck. So the way you want to rewrite that SCROLLING bit would to make it simple IF THEN statements. You'll need to translate it to Construct speak.

    IF Player.X > 500 AND Player.X < 900 THEN

    Scroll to Player.X;

    ELSE

    IF Player.X > 900 THEN

        Scroll to 900;

    ELSE

        Scroll to 500;

    END IF

    END IF

  • That's exactly what's happening farmerdwight. The thing is I had no idea how to exit a loop in Construct - I just started a few hours ago. Now I got the hang of it better :)

    I have another question tho -

    I have Text -> Set Position to (200, 200)

    then   Text -> Move 200 pixels at angle 90.

    The problem is that while i have specified a Y value at position, it will NOT execute Move 200 pixels. If i remove the 200 px on the Y it works fine. I tried different orders, spacing out the events, it didnt work. Is that a bug?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Xionor

    I'd need to see a .capx for the text block

  • The game loop is implicit in C2

    If you have programming background, consider that things work this way:

    While (true) {
        Event Sheet   
        Rendering
    }

    Which means that what you try to do is

    while (true) {
       Text.position(200,200)
       Text.move(200,90)
       Render()
    }

    Every game loop iteration, or simply said "every tick", you are repositionning your text back to (200,200) and then moving it.

    The result of this is that, Text will be at (200,400) then will be rendered

    If you inverse the order of event, you'll always see the text at (200,200) for the same reason.

    You probably need to go through a couple of tutorial.

  • Thanks Yann, I didn't realise that Construct2 events are While based. I read some into the manual and got everything to work just fine in the end : )

    Thanks for all the help everyone!

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