# eliminating a value from choose

Get help using Construct 2

### » Sun Sep 01, 2013 3:50 pm

I have a NPC that chooses 1 of 4 directions

0=(right)
90(down)
180(left)
270(up)

If NPC has chosen one of these already how do I eliminate it from the next choose expression.

I've given the NPC a "lastdirectionpicked" value I don't know the expression to take away the

set "directionmovement" to choose(0,90,180,270)

Thanks in advance
B
14
S
6
G
3
Posts: 83
Reputation: 4,278

### » Sun Sep 01, 2013 6:44 pm

Start of layout
Set "lastDirectionPicked" to "0"

do you trigger condition
set "chooseDirection" to "0,90,180,270"
(reset all possible choices)

set "chooseDirection" to replace("chooseDirection", "lastDirectionPicked", "")
(remove the last direction from those choices)

set "directionMovement" to tokenat("chooseDirection", int(random(3)), ",")
(choose a direction from the ones left at random)

set "lastDirectionPicked" to "directionMovement"
(keep track of direction just taken)
Ethan2013-09-01 18:48:07
B
43
S
23
G
21
Posts: 735
Reputation: 12,142

### » Wed Sep 04, 2013 1:12 pm

thanks ethan, not sure i understand but ill give it a go :)
B
14
S
6
G
3
Posts: 83
Reputation: 4,278

### » Wed Sep 04, 2013 5:03 pm

I once written an expression to do exactly that. Overkill nested choose FTW !
[code]choose(NPC.lastdirectionpicked = 0 ? choose(90, 180, 270) : 0, NPC.lastdirectionpicked = 90 ? choose(0, 180, 270) : 90, NPC.lastdirectionpicked = 180 ? choose(0, 90, 270) : 180, NPC.lastdirectionpicked = 270 ? choose(0, 90, 180) : 270)[/code]Basically, if choose() select the last direction of NPC, it choose again among the remaining three. If no direction was selected (i.e. NPC.lastdirectionpicked = -1 or something), it still picks one of the four possible choices.Magistross2013-09-04 17:07:18
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

Return to How do I....?

### Who is online

Users browsing this forum: dop2000, Metathronos and 19 guests