What am I doing wrong? Re: while loop

Get help using Construct 2

Post » Tue Nov 29, 2016 6:51 pm

B
10
S
3
Posts: 48
Reputation: 758

Post » Tue Nov 29, 2016 6:55 pm

C2 is already a giant While loop, So you don't need while at all. get rid of it and add an Else to the event for the NOT case.
ImageImageImage
B
71
S
21
G
221
Posts: 3,650
Reputation: 124,229

Post » Tue Nov 29, 2016 7:12 pm

C2 is already a giant While loop, So you don't need while at all. get rid of it and add an Else to the event for the NOT case.



What if this check is inside a triggered event? Then it isn't a part of the big C2 while loop.

Example: When a triggered event happens such as a ship is destroyed by a laser, you want to spawn a new ship in a random spot, but you don't want it to overlap another existing ship. So you just do a while-loop to keep creating the ship until it's not in a spot that's overlapping.
B
10
S
3
Posts: 48
Reputation: 758

Post » Tue Nov 29, 2016 7:23 pm

That's different code though - not what have here. Presumably the condition would stop quickly and the While will exit. The test code doesn't meet this requirement.
ImageImageImage
B
71
S
21
G
221
Posts: 3,650
Reputation: 124,229

Post » Tue Nov 29, 2016 8:05 pm

COGames wrote:Keeps getting hung up. :(


You have NO code that makes the 'while' untrue.
In general a 'while' is safe to use like this....

Local Variable 'check' = 0

Condition to check
Action Set check to 1

While
check = 1
...Empty condition
...Action Make a change
...Condition to check
...Action set check to zero

Or

Local Variable 'check'. = 0

If overlapping
set check to 1

While check = 1
...sub
...Action move the object
...Is NOT overlapping
...set check to 0
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912


Return to How do I....?

Who is online

Users browsing this forum: lolsuperscratch, RobertMKD, tarek2 and 9 guests