Odd randomized rule picker

BacktothisBacktothis Member, PRO Posts: 75
edited February 2014 in Working with GS (Mac)
The variables that are important:
TopSpawnLimit = 640
BottomSpawnLimit = 420
AdjacencyOffset = 60
SpawnLocation = somewhere between top and bottom spawn limits
State = 0 (initial), 1 (try to spawn upwards), or 2 (try to spawn downwards)

The rules in the spawner are in the following order:

Every 2 seconds on a timer{

if (State==0){
//pick random value for SpawnLocation
}

if (State == 1){
try{
//spawn upwards from current SpawnLocation at least AdjacencyOffset # of pixels if there is enough room
} else{
//spawn anywhere from TopSpawnLimit-2*AdjacencyOffset to BottomSpawnLimit
}
}

if (State==2){
try{
//spawn downwards from current SpawnLocation at least AdjacencyOffset # of pixels if there is enough room
} else{
//spawn anywhere from BottomSpawnLimit+2*AdjacencyOffset to TopSpawnLimit
}
}

State = random(1,2)
}

Now if I modify the State = random(1,2), and instead change it to State = random(1,1) or State = random(2,2), so that it always tries the spawn downwards state or always tries the spawn upwards state, it works perfectly. The spawns are never within AdjacencyOffset # of pixels of each other. But, if instead it's State = random(1,2), we get weird (SpawnLocation,State) pair transitions like

587,2 -> 606,1
598,2 -> 592,2
640,1 -> 621,2

I thought that maybe something was being processed out of order, but keep in mind it's not possible for 640 to go to 621 no matter which rule you apply. And indeed this behavior NEVER happens if you force State to always be 1 or always be 2, instead of varying between 1 or 2. So somehow allowing State to randomly alternate between 1 or 2 introduces behavior that does not seem logically possible. What could I be missing?


edit - And to be clear, all that has to be changed to go from working perfectly to weird behavior, is to change the change attribute function of random from random(1,1) or random (2,2) to random(1,2). Nothing else needs to be changed.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2014
    Let me put on my thinking cap... this looks complex!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @Backtothis I sent you a private message.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I took a look at the file but I'm finding it too dense. Sorry I can't help but I just don't have that kind of time right now.

    A couple things to note: (1) You're designing for Legacy iPhone so if you're wanting to publish to iPhone 5 and/or iPad, you'll want to use "iPhone" as the platform instead of "Legacy iPhone" and (2) I assume you realize that you've unlocked the spawner actor and it therefore is an instance that uses its own rules rather than the prototype rules found in the actor in the Actors' pane.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • BacktothisBacktothis Member, PRO Posts: 75
    Ah yes I found out about the legacy thing after the fact (my first app attempt lol) but i have a camera fix for that so it's no problem.
Sign In or Register to comment.