Random Object Spawn Issues

Discussion and feedback on Construct 2

Post » Thu Mar 07, 2013 3:41 pm

I'm having an issue spawning random objects. First, here's the section of my event sheet that isn't working as I hoped it would:



I have another event that constantly subtracts from the value "NextObject". When the value of "NextObject" reaches 0, the game should spawn a random object further along the path, just off the screen (it's an endless runner). But for some reason, it only spawns an object the first time, and always the first object on the list (Rocks1, which is the default value for the variable used to choose which object is spawned). After that first object... nothing.

I've also attempted setting this up with the different random object variables as sub events, but then nothing happens at all (even if I remove the "trigger once" conditions).

This is strange, because I use a very similar system to generate enemies which works fine. Only difference is the enemies each have their own countdown global variable, so no extra step that randomises which enemy is spawned. That's making me question whether the random variable is working? I can't see where I made a mistake though.

Any help would be greatly appreciated! Thanks for reading
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Thu Mar 07, 2013 3:42 pm

Aaaaand... I posted this in the wrong forum section. Sorry
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Thu Mar 07, 2013 3:58 pm

@silver

Have you tried int(random(5)) as unlike classic,C2 will not return an integer automatically?....
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Thu Mar 07, 2013 4:08 pm

That worked! Thanks!

For some reason the other sections where I've used 100 + random(1000) work fine though. They don't need to be 100 + int(random(1000)). Odd
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Thu Mar 07, 2013 4:17 pm

Coming from classic myself,I have been caught out by C2's love of floats a few times...lol.

If your other uses have been in regard to plotting x/y and you have pixel rounding on then that may explain why it has not surfaced yet..

Glad to help.
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260


Return to Construct 2 General

Who is online

Users browsing this forum: 99Instances2Go, MatheusCastellar and 6 guests