eliminating a value from choose

Get help using Construct 2

Post » 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,228

Post » 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
20
Posts: 735
Reputation: 12,027

Post » 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,228

Post » 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
71
S
30
G
25
Posts: 984
Reputation: 19,503


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 48 guests