Generating Random objects.

0 favourites
  • 4 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I've four objects and i want to generate random one at a time in my game, how to do that, i'm unable to think of a logic for it :(. Should be like this

    objects

    obj1, obj2, obj3, obj4

    System on every 2 tick generate random(obj1,obj2,obj3,obj4)

  • avinash, one way to look at it is that you want to pick a random number from 1 to 4, or 0 to 3, if you want to be zero-based <img src="smileys/smiley1.gif" border="0" align="middle" />

    Store this value in a local variable, and then use 4 sub-events to create the appropriate object based on the random number.

    For example, if the value is 1, create object A. If value is 2, create object B, etc.

    This gives you the flexibility of being able to do other object-specific logic at the same time, in case you needed to run an extra step whenever you spawned object 4 for example.

    Hope this helps!

  • Unfortunately if you did it that way you'd have to manually set

    If var = 1

    Create object 1

    If var = 2

    Create object 2

    etc.

    The best way to do it is having the same object with different animations and set the animation speed to 0 (for instace one for health, one for mana, etc).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Put the objects in a family. When you create a family object it will pick a random one.

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