How to set different delay for each object to spawn another?

Get help using Construct 2

Post » Mon Dec 08, 2014 9:45 am

Hello!

I want each object to spawn another object with different intervals. In the capx I included the interval time is taken from instance variable that is set to equal object UID.

Sprite with UID 0 should spawn another object after every 0 seconds.
Sprite with UID 1 should spawn another object after every 1 seconds.
Sprite with UID 4 should spawn another object after every 4 seconds.
But for some reason it does not work :/
Each Sprite spawns Sprite2 after the same amount of time.
You do not have the required permissions to view the files attached to this post.
B
13
S
2
G
1
Posts: 24
Reputation: 953

Post » Mon Dec 08, 2014 10:11 am

There's a fair bit wrong with that code. Firstly you're doing the loop every tick. Secondly, in the function you're accessing param #0, 1, or 4 but you're only passing one param (sprite.delay). You're also not picking any Sprite objects in the function, so all of them get picked and spawn the Sprite2 objects. I wouldn't use a sprite's UID as they are not fixed (maybe in a trivial test like this but not in a real game). Even so a delay of 0 would be just a stream of Sprite2's coming out. There's more, but how about start over..

PS: I only used IID as a way of getting different delay values, but you could use choose() or random() or anything else.
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Dec 08, 2014 11:21 am

@codah
Thank You!
Did not even think about timer behavior. This solves my problem very easily :)
And have no worries, I was using UID's just for testing purposes ;)
B
13
S
2
G
1
Posts: 24
Reputation: 953


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, MPPlantOfficial, Sup with that? and 60 guests