Generating Random objects.

Get help using Construct 2

Post » Wed Sep 11, 2013 8:36 pm

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)
B
4
Posts: 21
Reputation: 626

Post » Wed Sep 11, 2013 8:44 pm

@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

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!
B
8
S
3
G
1
Posts: 8
Reputation: 1,225

Post » Wed Sep 11, 2013 9:30 pm

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).
B
123
S
43
G
41
Posts: 847
Reputation: 28,206

Post » Wed Sep 11, 2013 11:05 pm

Put the objects in a family. When you create a family object it will pick a random one.
B
46
S
14
G
7
Posts: 603
Reputation: 8,116


Return to How do I....?

Who is online

Users browsing this forum: Kermad, yiuyiu6666 and 19 guests