0 Favourites

Array issue. Need help.

  • Hi,

    I want to generate random objects at a particular interval. This is what I have done:

    1. I have created one object.

    2. Added animations to that, which are the other objects that I want to appear randomly.

    3. Created an array.

    4. On Start of Layout, <array name> push back <animation name> on X axis. I did this for all the animations.

    5. System > Every 0.7 seconds > System > Create Object <object name> on Layer 1 at <co-ordinates>

    6. <Object name> > Set animation to arrayName.At(floor(random(arrayName.Width))) (play from beginning)

    But my problem is, though all the animations appear randomly, almost 90% of the time, just the first animation keeps spawning.

    How can I make it that everything is random and one object is not overly dominated?


  • The first thing that comes to mind is if you've set the width of the array correctly? If you add an array it is set to (10, 1, 1) initially. You can access the values in the array's tab, or via event prior to pushing the animation names.

    If it is set to 10, then any push adds to the size, and when randomizing it will select the first ten cells a lot more often than your animation entries.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Amazing! Thanks! Yeah. I reduced the width to the number of animations I had added and now its fine. :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
300 118,423
blackhornet's avatar
Unread hot topic
0 Favourites
Spam issue
201 16,834
Tom's avatar
Tom Construct Team Founder
Unread hot topic
157 12,693
megatronx's avatar