Random number help please urgent

FirstDanFirstDan Member Posts: 208
edited February 2012 in Working with GS (Mac)
Hi all

i have an actor that spawns a actor self.pos.x to random(30,290) which works fine
but i want to do the following but don't how to do it in GS:

Variable called game.randomPosX = random(30,290)

first instance: actor gets spawned at 280, 270, 275 etc,
what i want is that

if the the actor was spawned at 280, then the next instance i want it to spawn on the left hand side of the screen.

example

if randomposx >=0 and <=160 the actor has spawned on the left hand side
if randomposx >=160 and <= 320 the actor has spawned on the right side

thanks

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi @FirstDan

    By the sound of it you'll need to split it up into two spawning actions, right, then left, then right, etc; - if I've understood you correctly.

    So something like: Make a boolean attribute called Switch

    When Switch is false
    Change attribute game.randomPosX to random(161, 319)

    -- then spawn your actor with it's x pos. as randomPosX
    change attribute Switch to true

    When Switch is True
    Change attribute game.randomPosX to random(1, 159)

    -- then spawn your actor with it's x pos. as randomPosX
    change attribute Switch to false

    hope that's what you're after and it helps out...


    ----------------------------------------------
    http://davidgriffinapps.co.uk/

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • FirstDanFirstDan Member Posts: 208
    @gyroscope - thank you so much for your help, it works, however my actors get spawned together, i would like u position to have a distance between the
    first and second spawn..:)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2012
    That's no prob; put in Timer behaviours, set to After how many seconds you want, one just after "When Switch is false" and the other just after "When switch is true"

    If you want the first spawn straight away, put this first:

    Change attribute game.randomPosX to random(161, 319)
    -- then spawn your actor with it's x pos. as randomPosX
    change attribute Switch to true

    ---then...

    Rule
    When Switch is true
    Timer After 5 seconds
    Change attribute game.randomPosX to random(1, 159)
    -- then spawn your actor with it's x pos. as randomPosX
    change attribute Switch to false

    Rule
    When Switch is false
    Timer After 5 seconds
    Change attribute game.randomPosX to random(161, 319)
    -- then spawn your actor with it's x pos. as randomPosX
    change attribute Switch to true

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.