help on "choose"

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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!

  • 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. :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Or go for some overkill expression :

    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)

    <img src="smileys/smiley36.gif" border="0" align="middle" />

  • Magistross

    I must try this! :)

  • hm...

    why is this is not working?

    lastChoice = 90

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

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