# Cycle/wrap a number

Get help using Construct 2

### » Fri Feb 28, 2014 12:53 am

Is there an expression that can cycle a variable between two numbers?

ex.
x = cycle(3.5,0,1); // sets x at 0.5
B
13
S
4
Posts: 61
Reputation: 1,028

### » Fri Feb 28, 2014 2:39 am

Message: Aurora Australis can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Are you talking about the random command? If so, set each number as an option. Random can be found in several tutorials.

https://www.scirra.com/tutorials/search?q=random
B
32
S
10
G
2
Posts: 155
Reputation: 3,070

### » Fri Feb 28, 2014 2:42 am

Nay. I was wondering if there is an expression or function that can keep a number within a range without "clipping" it at the maximum or minimum value. Say I want a number to stay between 0 and 8, and the number i enter is 10. it returns as 2, not 8.
B
13
S
4
Posts: 61
Reputation: 1,028

### » Fri Feb 28, 2014 2:53 am

You could try

min = 0;
max = 1;
value = 3.5;
x = (value % max) + min

But i'm not %100 on this. I tried this a few times with different result. Higher than max seems to have no troubles.

I have to admit. If this works it would seem that a cycle function would be kind of a silly idea; since this is a pretty minimal expression. We don't really use function such a multiply(var1, var2). Unless of course there is some serious optimization.
B
94
S
18
G
9
Posts: 2,457
Reputation: 15,177