A single "While" stops my whole game.

Get help using Construct 2

Post » Thu May 16, 2013 10:48 pm

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?Xionor2013-05-16 22:49:42
B
10
S
3
Posts: 233
Reputation: 1,537

Post » Thu May 16, 2013 11:21 pm

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.
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
112
S
20
G
8
Posts: 741
Reputation: 13,631

Post » Thu May 16, 2013 11:33 pm

yeah the capx would be helpfull
B
18
S
6
G
3
Posts: 197
Reputation: 4,129

Post » Thu May 16, 2013 11:37 pm

@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

B
10
S
3
Posts: 102
Reputation: 1,888

Post » Thu May 16, 2013 11:57 pm

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?
B
10
S
3
Posts: 233
Reputation: 1,537

Post » Fri May 17, 2013 12:23 am

@Xionor

I'd need to see a .capx for the text block
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Fri May 17, 2013 12:50 am

The game loop is implicit in C2

If you have programming background, consider that things work this way:
[code]While (true) {
    Event Sheet   
    Rendering
}[/code]


Which means that what you try to do is
[code]while (true) {
   Text.position(200,200)
   Text.move(200,90)
   Render()
}[/code]

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.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri May 17, 2013 1:31 am

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!
B
10
S
3
Posts: 233
Reputation: 1,537


Return to How do I....?

Who is online

Users browsing this forum: badmoodtaylor and 13 guests