# help on "choose"

Get help using Construct 2

### » Fri May 24, 2013 3:21 pm

Hello,

I use this expression for my spawning elements:
choose(0,90,180,270)
wich gives them a angle of movement, and this works ok but since its random choice i have situation that its been repedetly choosen same angle several times in the row.

Is there a way to adjust this formula so that it chooses all except the last choice?

eg.
So that if the last choice was 0, next choice can be between 90,180,270 and if now is 180 then next one can be amongst 0,90,270 and so on...

Thanx!

B
34
S
15
G
3
Posts: 820
Reputation: 6,491

### » Fri May 24, 2013 3:30 pm

You could do something like this:

lastChoice = -1
choice = -1

.. spawn stuff
.. while(lastChoice = choice)
.... choice = choose(0,90,180,270)
.. lastChoice = choice

The choice variable now holds the angle, which is not same as the last angle that was randomed. Should work in theory, never tested it. :)vee412013-05-24 15:35:19
B
24
S
9
G
7
Posts: 756
Reputation: 7,342

### » Fri May 24, 2013 7:14 pm

Or go for some overkill expression : [code]choose(Sprite.Angle = 0 ? choose(90, 180, 270) : 0, Sprite.Angle = 90 ? choose(0, 180, 270) : 90, Sprite.Angle = 180 ? choose(0, 90, 270) : 180, Sprite.Angle = 270 ? choose(0, 90, 180) : 270)[/code] Magistross2013-05-24 19:15:16
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

### » Fri May 24, 2013 10:29 pm

@ Magistross

I must try this! :)
B
34
S
15
G
3
Posts: 820
Reputation: 6,491

### » Sat May 25, 2013 10:44 pm

hm...

why is this is not working?

lastChoice = 90
set nextChoice choose(0,90,180,270) <> lastChoice

irina2013-05-25 23:05:10
B
34
S
15
G
3
Posts: 820
Reputation: 6,491

### Who is online

Users browsing this forum: samueledev and 23 guests