How do I Spawn Multiple Random Objects

Get help using Construct 2

Post » Sun Jan 11, 2015 8:17 pm

When my player collides with a crate, the crate spawns a treasure from the Treasure Family which has 8 different treasure objects. How can I spawn more than 1 treasure object from the family when the player collides with a crate?

I.e: Sometimes a crate will only spawn 1 treasure from the family. Sometimes 3 different treasures from the family, etc. etc. I'd like to spawn 1, 2 or 3 different objects.

Any help would be greatly appreciated.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Sun Jan 11, 2015 8:55 pm

Do a system repeat action and set the repeat count to something like random(1,4)?
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Sun Jan 11, 2015 9:42 pm

Can't get that to work. Tried changing things around but It only spawns 1 instance or i get an error message about the repeat.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Sun Jan 11, 2015 10:12 pm

Well, I made a little example - it's possibly a better idea to use animation frames for different treasure and instance variables if it's needed for value, etc. But the spawning of different amounts seems to work just fine.
You do not have the required permissions to view the files attached to this post.
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Sun Jan 11, 2015 11:44 pm

you can use the following for the amount of object that will be dropped: int(random(1,4))
This will give the number 1, 2 or 3 as a result.

You can use this with the For loop(System/Loops/For) with the following parameters:
Name: "drop items" (or whatever you want)
Start index: 1
End index: int(random(1,4))
B
15
S
4
Posts: 43
Reputation: 1,022


Return to How do I....?

Who is online

Users browsing this forum: max2612 and 7 guests