Array issue. Need help.

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

    Thanks.

  • Try Construct 3

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

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

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