spawning 2 actors

Maniacus

  • Posts: 69
I have 2 actors spawning off the screen moving to the right. One is on the top and the other is the bottom. I'm currently using the random number system to spawn them. The issue is it will spawn numerous ones of one of the actor in a row. Like 5 or more. Is there a efficient way to do this?

Hectate

  • *
  • Posts: 4645
We'd need to see your behavior to understand what you're doing vs. what you're intending. Can you share a screenshot?
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Maniacus

  • Posts: 69
Sorry. Here it is.

Hectate

  • *
  • Posts: 4645
I just realized that what I understood you to say was probably not what you mean.
You're saying that it will spawn the actors correctly (the frequency of creation is fine) but the actor chosen is often the same actor when you expect it to be the other.

Hrm, this one is tricky because well, with true randomness you can't really know if it's actually being random (and you got a string) or not. Does it always pick the same one several times in a row or is it just...randomly? lol
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Maniacus

  • Posts: 69
Yeah lol  quite a bit of the time it will randomly spawn the same one several times . I dont mind two or three of the same actor in a row. Even if they could just alternate in spawning would be good.

csharporbflat

  • Posts: 97
This is basic probability.

Think of flipping a coin

you have a 50, 50 chance of getting heads or tails.

However there is nothing to say you wont get 10000 heads before you see a tail.

Samething think applies with a random binary number.

So I see nothing wrong with the code. Just remember that computers use pseudorandom numbers, so if you counted the number of times each one generated, and generated them 200000 times you might end up with something like 100019 of one and 99981 of the other, but if you do those as percentages, you basically have 49.9999% for one and 50.0001% for the other.  So you will never truely get 50/50.

There is a way to make it so it will always switch, do one after the other, but then it wont be random

Maniacus

  • Posts: 69
Okay, So let's say remove the random spawn. If i wanted actor one to spawn then next have actor two  spawn then back to actor one. That would work for me. How would I do that?

Hectate

  • *
  • Posts: 4645
A simple boolean would work.

If (isTimeForActor1 == true)
 - spawn Actor 1
- set isTimeForActor1 to false)
else
- spawn Actor 2
- set isTimeForActor1 to true
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Maniacus

  • Posts: 69
Alright thanks for your help. I really appreciate it.