For Each (random)

0 favourites
  • 11 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hi guys. How to implement For Each (random)?

    Example:

    List: 1,2,3,4,5,6,7,8,9

    For Each (random) : 3,7,2,1,9,5,8,4,6

  • Can you give this some context; do you wish to random bunch of object IIDs, random numbers or what are you trying to achieve?

  • i think he wants to do a foreach event ordered by random. if this is the case, you can use foreach (ordered) and in the expression use sprite.someinstancevariable ascending and on creation of the sprite just set its someinstancevariable to floor(random(999999)) for example. very pseudo random but as good as it can be im afraid.

  • Random For Each all objects.

    <img src="http://i50.tinypic.com/oa845d.png" border="0" />

  • why you used "for" in the first event when you can make a "repeat 10 times" event :)

    also check my answer above, it should be fine.

  • I believe "Choose" is what you are looking for:

    choose(a, b [, c...])

    Choose one of the given parameters at random. E.g. choose(1, 3, 9, 20) randomly picks one of the four numbers and returns that. This also works with strings, e.g. choose("Hello", "Hi") returns either Hello or Hi. Any number of parameters can be used as long as there are at least two

    https://www.scirra.com/manual/126/system-expressions

  • ranma

    why you used "for" in the first event when you can make a "repeat 10 times" event :)

    I just started learning to Construct 2, but I have development experience C #, PHP, JS.

    Not quite accustomed to the approach to the development of Construct 2.

    You suggest a good solution. I just do not know how to set sprite.someinstancevariable to create a sprite. Show how to do it.

  • when you create a sprite, select it and on the left pane (properties) you should have the ability to add a new instance variable to it, add it, call it "whatever" :)

    then in the event sheet when you create the sprite just set its "whatever" instance variable to the floor(random(9999)) and in the next event make a foreach ordered, choose the sprite, ordered by expression sprite.whatever ascending

  • Thank you friend! I did not know that you can sort by instance variable. Construct 2 pleases more and more :)

  • I'd like to add that you can do ranma's method without an instance variable. Just use random(1) as the expression in for each ordered.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • oh lol, didnt think of that, but that actually seems to be true :D

    gj rojo! :D

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