Infinite Loops - While

Just started using Construct 2? Post your questions here

Post » Thu Feb 02, 2017 5:17 am

Hi.

How would I set up an infinite loop with a condition to infinitely cycle through 29 values until the condition is no longer true?

I've set up the array with the 29 values, but for some reason I'm having trouble nesting the For Each Value under While.

What's the best way to code this?

We could obviously try something with less values and just appending a text object.

This is my first time using While, so I may not be up on all the syntax possibilities.
B
39
S
20
G
18
Posts: 264
Reputation: 12,983

Post » Thu Feb 02, 2017 9:12 am

General flow :

Set premise to false

While
Test premise
.......... change something
.......... test change
........................... set premise false or true based on change

But in your case, chances are that you dont need a 'while', if we speak about a 1 dimensional array.

Array > Contains value 'value'
................. in the actions the index of that value is stored in the expression Array.IndexOf('value')

Otherwise.

Local variable 'counter' ... number .. = 0
Local variable 'check' ... number .. = 0

While
'check' = 0
_______ Array .. Compare at XY ... x = counter .. y = say 1 ... compare to what you wanna compare
_______________Set 'check' to 1
_______System > Compare 2 values ... counter ... is the same as ... Array.widht - 1
_______________Set 'check' to 1
_______ System > Every tick
_______________add 1 to counter
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Post » Thu Feb 02, 2017 6:38 pm

I did not 'solve' anything for you. I see you say in another topic:

Basically, I was just doing a ship tilting animation when pressing arrow keys left and right and I wanted it to animate back when the arrow key was released. I coded something with variables that works flawlessly while breaking up the 29 total frame animation into individual frames linked up to a specific variable (my way of keeping track of the frame number).


A 'while' & 'animation frames' dont match. Simple because a 'while' always happens in 1 tick and 'animation frames' happen over several ticks.

I suppose you want to play some 'basic animation' when the 'tilting animation' returns to its 'zero' frame.

Set the 'basic animation' to looping in its property's.

Now all you need is:

Sprite > Is playing 'tilting animation'
Sprite > Compare frame .. = 0 ?
System > Trigger once while true
______________ Sprite > Set animation .. 'basic animation'

If i understand what you try to do.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests