eliminating a value from choose

0 favourites
  • 4 posts
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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)

  • thanks ethan, not sure i understand but ill give it a go :)

  • I once written an expression to do exactly that. Overkill nested choose FTW !

    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)

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)