[solved]How do I work with while loops?

Get help using Construct 2

Post » Mon Jul 20, 2015 12:18 pm

Whatever I do I get some "Unresponsive script" error. Is there some kind of example for using while loops?
Last edited by sivricmarijan on Mon Jul 20, 2015 4:31 pm, edited 1 time in total.
B
9
S
4
G
3
Posts: 157
Reputation: 2,300

Post » Mon Jul 20, 2015 12:40 pm

Could you share the events or describe them?
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816

Post » Mon Jul 20, 2015 1:56 pm

A while loop needs an exit condition or a "break" statement (stop loop). Otherwise it'll loop infinitely and cause your script to hang.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Mon Jul 20, 2015 3:35 pm

I want to move the green dot ("player" sprite) to move until the left end of the background sprite (or layout).

Image
B
9
S
4
G
3
Posts: 157
Reputation: 2,300

Post » Mon Jul 20, 2015 3:37 pm

I was also thinking it's an infinite loop but I don't know where to put the stop loop
B
9
S
4
G
3
Posts: 157
Reputation: 2,300

Post » Mon Jul 20, 2015 3:48 pm

Try to put the condition "player is overlapping background" directly into the "while" event instead of a sub-event. Right now the while loop doesn't have any conditions associated with it.
B
38
S
16
G
6
Posts: 537
Reputation: 7,582

Post » Mon Jul 20, 2015 4:00 pm

It works now but it only "teleports" from the center of layout to the left. I want it to move instead...like some kind of animation!
B
9
S
4
G
3
Posts: 157
Reputation: 2,300

Post » Mon Jul 20, 2015 4:20 pm

Use a boolean instance variable called "Sliding" or something like that. When you click on it, set Sliding to true. Then do another event, if Sliding is true, move it a little bit like you have now. Then every time through your game loop it will move just a bit, making it like an animation.
B
10
S
2
Posts: 33
Reputation: 710

Post » Mon Jul 20, 2015 4:24 pm

I have finally made it using the Bullet and BoundToLayout behavior:

Image

Thanks guys and girls!!! You are THE BEST!!!
B
9
S
4
G
3
Posts: 157
Reputation: 2,300

Post » Mon Jul 20, 2015 4:32 pm

sivricmarijan wrote:It works now but it only "teleports" from the center of layout to the left. I want it to move instead...like some kind of animation!

I think it's because all loop running at the same time
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816


Return to How do I....?

Who is online

Users browsing this forum: plinkie and 16 guests