GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Spawning Issues

SarahbushSarahbush Posts: 55Member, PRO

Firstly Merry Christmas to all my Gamesalad Family!!

Im making a game which spawns balls from the bottom of the screen to the top. Ive got 5 different types of balls and have a spawn actor which every 0.5-2 seconds spawns one of the balls.
It works fine but every so often when i test it they all come out in one long line and merge together and i have to refresh it several times until its ok. I don't know what to do as the code is really simple thats literally all i have done to the game and i can't see where its going wrong.

Does anyone have an idea?

Ive started again and its doing the same thing.

Sarah

Comments

  • gyroscopegyroscope I am here.Posts: 6,577Member, Sous Chef, PRO
    edited December 2015

    @Sarahbush Hi Sarah, hope you had a great Christmas too!

    It's a timing issue because you've got the spawning between two times. Can you post your rules please?

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

  • SarahbushSarahbush Posts: 55Member, PRO

    Im sorry about the delay! Thanks @gyroscope for replying!

    so basically I've got 4 different actors (balls) ..

    Ive created a spawn actor - within the spawn actor i have an integer attribute called Spawn Balls.
    Then i have a Timer behaviour which says every 0.5 - 2 seconds change spawn Balls attribute to random (1,4)

    Then i have a rule for each ball (still within the spawn balls actor) which says if self.spawnballs = 1, spawn ball 1 .. etc . so one of these rules for each of the balls that I'm spawning.

    Does that all make sense - sorry if not!

    so its odd as it seems like really simple code but as soon as i press preview it will mostly be ok but the odd time they all merge together up the screen so i have to keep refreshing it.

    Hope you can help :)

    Thanks again,

    Sarah

  • gyroscopegyroscope I am here.Posts: 6,577Member, Sous Chef, PRO

    @Sarahbush Hi again, Sarah - couple more questions first - once these balls are spawned do they move or stay in position? And if they stay in position, you presumably have different x and y coordinates for each of the 4 balls? If not, you're going to have all the balls spawning on top of each other.

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

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member

    I agree the issue is that the next ball could spawn in .5444 or such not giving enough time for the previous ball to move which spawned at .5555. Without knowing the specific desired mechanics We can't give you the solution you need.

  • SarahbushSarahbush Posts: 55Member, PRO

    Hi there, sorry should have mentioned that .. the spawn actor is at the bottom of the screen and the all the balls spawn to the top ..

    They each have an accelerate rule - direction 90 and acceleration 250.

    Its odd as when it works its perfect it just seems to glitch and they all merge together.

    Thanks of your time - much appreciated :)

  • SocksSocks London, UK.Posts: 12,822Member

    @Sarahbush said:.
    Then i have a Timer behaviour which says every 0.5 - 2 seconds

    'Every' is a fixed value, it cannot be 0.5 - 2 seconds.

  • SarahbushSarahbush Posts: 55Member, PRO

    i meant its Every random (0.5-2) seconds

  • SarahbushSarahbush Posts: 55Member, PRO

    so basically i was hoping that every random (0.5 - 2 seconds) a ball would be spawned (one of the four i have) and scroll up the screen - don't mind if they're repeated or anything ..

    it just glitches and i can't figure out why .. :(

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member
    edited January 2016

    Nope random will give any number between .5 and 2 which includes decimal places. That is how random works. If you want four places you will need another random generator to out one of the four times you want. The only way you keep whole numbers on a random is to use an integer as it can only do whole numbers. This is why understand what attributes do what.

    Real attribute = numbers with decimal places
    Integer = whole numbers only and can be negative
    Index = whole numbers and will not go negative

    So

    Change attribute real to random (.5,2) will generate any value in decimal increments

    Change attribute integer to random (-1,4) will generate any value in whole numbers ( and negative values if specified) increments -1,0,1,2,3,4

    Change attribute index to random (1-4) will generate any value in whole number increments
    1,2,3,4 (can do the same with integer)

  • SocksSocks London, UK.Posts: 12,822Member
    edited January 2016

    @Sarahbush said:
    i meant its Every random (0.5-2) seconds

    This won't work as 'Every' is a fixed value . . . . . this will choose a random value of 0, 1 or 2 (random works with whole numbers) and use that value 'Every' time.

  • SocksSocks London, UK.Posts: 12,822Member

    @Lost_Oasis_Games said:
    Change attribute real to random (.5,2) will generate any value in decimal increments

    This will also give you 0, 1 or 2, even if you use a real attribute, the random number generation process generates only whole numbers, even if you are storing them in a real attribute.

  • gyroscopegyroscope I am here.Posts: 6,577Member, Sous Chef, PRO
    edited January 2016

    @SarahBush As @Socks says; in this case you'd have to times it then divide by the same amount

    Example (random(5,20))/10 (making sure the attribute the result its going in is real).

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

  • SarahbushSarahbush Posts: 55Member, PRO

    thank you everyone for your help! i think my brain may explode with all the information. haha
    i do understand what you're saying (i think) so ill play around now and see what happens.

    Thanks again

  • SarahbushSarahbush Posts: 55Member, PRO

    I've changed the spawning to every 1 second - this is working perfectly.

    Thank you.

    :)

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member

    @Socks said:

    @Lost_Oasis_Games said:
    Change attribute real to random (.5,2) will generate any value in decimal increments

    This will also give you 0, 1 or 2, even if you use a real attribute, the random number generation process generates only whole numbers, even if you are storing them in a real attribute.

    Ah, I need to read up on the gamesalad glossary again. Thanks.

  • crestwoodgamescrestwoodgames Posts: 191Member

    The only way I can see randoms to work in decimals is by starting with large numbers and then dividing.

    For instance. Lets say you wanted to have a random decimal between 1 and 6.

    2 Variables. start_Number and final_Number.

    change attribute
    start_Number to random(100,600)
    change attribute
    final_Number to prec((start_Number/100),2)

    Might be an easier way to do it, but this should work I would think.

  • SocksSocks London, UK.Posts: 12,822Member

    @crestwoodgames said:
    The only way I can see randoms to work in decimals is by starting with large numbers and then dividing.

    For instance. Lets say you wanted to have a random decimal between 1 and 6.

    2 Variables. start_Number and final_Number.

    change attribute
    start_Number to random(100,600)
    change attribute
    final_Number to prec((start_Number/100),2)

    Might be an easier way to do it, but this should work I would think.

    You could just do:

    random(100,600)/100

  • crestwoodgamescrestwoodgames Posts: 191Member

    dang it @Socks

Sign In or Register to comment.