Random object spawn not spawning randomly.

SWhite92

  • Posts: 15
Hi,
I've been experimenting with a random spawn code, where the game places objects depending on a random number that is chosen. However, the code works, but will stop spawning randomly. Sometimes it will spawn 3, sometimes it will spawn 15, but never goes on indefinitely.

Anybody got any input on this? It's the only thing stopping me from finishing my game.

Thanks.

linai

  • *
  • Posts: 28
Since you only have two options, I would probably change your "otherwise if" into "otherwise," since it is theoretically possible that you would get neither condition (no hurdle will be spawned if you randomly generate "2" on the "if" and "1" on the "otherwise if".) Possibly better (more flexible) would be to store one randomly generated number in an attribute before the "if" and compare its value in the "if / otherwise if." Currently, you will eventually run out of "hurdles," since they will not always be replaced...

Don't know for sure that is causing the effect you're seeing, but thought i'd mention it (it's likely the culprit).

« Last Edit: May 06, 2014, 07:56:16 pm by linai »

sdieters

  • Posts: 2068
why do you randomize for the same actor?

this code can be created way easyer:

when created,
trigger event create hurdle

when create hurdle happens
do after 2 seconds
~create hurdle at (x and y)
~set x speed to -(desired speed) for last created actor << not sure why you use push force?

if last created actor leaves screen,
kill last created actor
trigger event create hurdle
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

SWhite92

  • Posts: 15
Thanks Linai, I'll change the code around and let you know what happens.

Sdieters, this is a snippet of code I have from my full game, I created another scene just to try this in. Originally there are three hurdles, and the only way I could get them to infinitely spawn is by making ten different hurdles and having a huge amount of code. Literally couldn't find any other way around it.

There are three positions originally, so instead of a random number between one and two, it would also have three.

Oh, I also use push force as my character is standing still, they would be the only moving objects. They then get killed when removed from the screen. Thanks for the reply though dude.

SWhite92

  • Posts: 15
Linai, the attribute method worked straight away, thanks a lot! :)