How do I spawn a random Object from a Set

Get help using Construct 2

Post » Mon Jan 28, 2013 8:46 am

Hey,

I searched the forum but dont really found anything that fits for me, or i dont really understand cause of language problems I guess.

Here is my problem:

I created 3 Objects at the moment, should be even more in the future, which are weapons and I want to spawn a random weapon every X second.

I want to use the System->Every Second Action and a blank sprite as a spawn point.

What do I need to do? Thanks in advance :)

Beaverlicious

PS: Sorry, if my english isnt perfect! :)



Image
Check out our start-up and configure your own helmet in true 3D.
B
42
S
11
G
11
Posts: 1,152
Reputation: 9,886

Post » Mon Jan 28, 2013 9:48 am

You could use families; put all weapons in 'Weapons' family and use event 'Create Object' on the family. I recall this creates random member of the family.

Other option would be to put all weapons in separate frames/animations of single sprite and on creation randomize the animation.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Mon Jan 28, 2013 11:40 am

Thx for the fast reply:)

The problem is, that i can't make families, because i don't have a license at the Moment. Need to save money first:)

I don't want to use different animations as well, because i did it with objects already. Isn't there another Solution? Something like a randomize Event. Object 1,2,3 randomize or something!:)
Image
Check out our start-up and configure your own helmet in true 3D.
B
42
S
11
G
11
Posts: 1,152
Reputation: 9,886

Post » Mon Jan 28, 2013 11:59 am

There's no built-in way to select random objects, but you could make something yourself fairly easily:

Create a global variable called randomiser, set it to 0

- Every X seconds -> Set global variable randomiser to ceil(random(3))
> Compare global variable randomiser = 1; trigger once -> Spawn object 1; set randomiser to 0
> Compare global variable randomiser = 2; trigger once -> Spawn object 2; set randomiser to 0
> Compare global variable randomiser = 3; trigger once -> Spawn object 3; set randomiser to 0
B
56
S
15
G
10
Posts: 910
Reputation: 11,942

Post » Mon Jan 28, 2013 4:46 pm

Hey, reads itself pretty logical, but what does ceil mean?

Thanks a 1000 times guys :)
Image
Check out our start-up and configure your own helmet in true 3D.
B
42
S
11
G
11
Posts: 1,152
Reputation: 9,886

Post » Mon Jan 28, 2013 5:05 pm

Ceil just means that it rounds the number up, as opposed to floor which rounds down, or round which rounds to the nearest whole.
B
56
S
15
G
10
Posts: 910
Reputation: 11,942

Post » Mon Jan 28, 2013 5:47 pm

thank you, thank you, thank you :)

Used the code you wrote and i guess it works! Tried it a couple of times, didnt think theres a system :)
Image
Check out our start-up and configure your own helmet in true 3D.
B
42
S
11
G
11
Posts: 1,152
Reputation: 9,886


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 20 guests