help on "choose"

Get help using Construct 2

Post » 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
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » 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
8
G
7
Posts: 756
Reputation: 7,192

Post » 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
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Fri May 24, 2013 10:29 pm

@ Magistross

I must try this! :)
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » 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
26
S
11
G
2
Posts: 669
Reputation: 5,038


Return to How do I....?

Who is online

Users browsing this forum: YoHoho and 15 guests