Create actor every random second

Costaah

  • Posts: 75
Hello,

I'm trying to create an actor every random second but it's not working...  Let me explain the situation:

In the game, meteorites keeps falling down. I want them to fall every time between 0,5 and 1,5 seconds but the time must change every second. So I made an attribute called Attack Time. But I can't make it fix!! The attribute changes but the system doesn't keep reading the value of the attribute all the time, it just uses the first value. If I put the code in a 'update' part, my flash is crashing because it creates millions of meteorites ate the same time.

Im so confused!!  :-\

I tried it in a few ways, right now i got this code:





Rares

  • Posts: 216
do every random number between 50 and 150 / 100
create meteorite
Last version (0.1.5) of my now cancelled game:
http://www.stencyl.com/game/play/27241

Costaah

  • Posts: 75
do every random number between 50 and 150 / 100
create meteorite

Whenever I do that, i feel like when I test the game, it generates a random number and keeps using the same number. The number has to change all the time. Like: after 1 second 1 meteor comes, then after 0.5 second 1 meteor comes etc...


sdieters

  • Posts: 2068
if i am correct, you cant change the amount of time in a timed event.
use custom events instead.

this is the making of my fully customizable actor span system, but in this first part, the first 10 minutes will be about spawning an actor every x seconds, but you can alter it by making the SpawnDelay number attribute change to a random number between 50 and 150/100 after the actor is created.

also, im just curious, but why would you first set the random number to somwhere between 50 and 150, and then devide it by 100?

this is the tutorial i was talking about
> https://www.youtube.com/watch?v=kCRMZowd37Y

Quote
Whenever I do that, i feel like when I test the game, it generates a random number and keeps using the same number. The number has to change all the time. Like: after 1 second 1 meteor comes, then after 0.5 second 1 meteor comes etc...

it happens every now and then the the random number generator picks the same number a couple of times in a row. you can print the value after setting it to a random number to see the outcome.
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

Costaah

  • Posts: 75
if i am correct, you cant change the amount of time in a timed event.
use custom events instead.

this is the making of my fully customizable actor span system, but in this first part, the first 10 minutes will be about spawning an actor every x seconds, but you can alter it by making the SpawnDelay number attribute change to a random number between 50 and 150/100 after the actor is created.

also, im just curious, but why would you first set the random number to somwhere between 50 and 150, and then devide it by 100?

this is the tutorial i was talking about
> https://www.youtube.com/watch?v=kCRMZowd37Y

Quote
Whenever I do that, i feel like when I test the game, it generates a random number and keeps using the same number. The number has to change all the time. Like: after 1 second 1 meteor comes, then after 0.5 second 1 meteor comes etc...

it happens every now and then the the random number generator picks the same number a couple of times in a row. you can print the value after setting it to a random number to see the outcome.

I'll check out the youtube video.

I googled about random float number and came across this: http://community.stencyl.com/index.php?topic=25130.0
Thats why I divide it.

NexusxAlpha

  • Posts: 157
first time back in a while so im a 'lil rusty but if i remember correctly you cannot do every <random number> seconds as it will take first randomly generated number when the function is called for the first time, and use that.

you could use this way

make an number attribute called spawn timer

then...

when created
<spawn timer> == random between 1 and 10

make an attribute called 'spawn seconds'

do every 0.1 seconds
>add 1 to <spawn seconds>

then make an if statement and say

if <spawn seconds> >= <spawn time>
create <actor>
set <spawn timer> to random number between 1 and 10
set <spawn seconds> to 0

hope it helps you, im sure this will work as i used to use it a lot.

Costaah

  • Posts: 75
first time back in a while so im a 'lil rusty but if i remember correctly you cannot do every <random number> seconds as it will take first randomly generated number when the function is called for the first time, and use that.

you could use this way

make an number attribute called spawn timer

then...

when created
<spawn timer> == random between 1 and 10

make an attribute called 'spawn seconds'

do every 0.1 seconds
>add 1 to <spawn seconds>

then make an if statement and say

if <spawn seconds> >= <spawn time>
create <actor>
set <spawn timer> to random number between 1 and 10
set <spawn seconds> to 0

hope it helps you, im sure this will work as i used to use it a lot.

This worked!! Thanks