Problem getting a timer to update to a changed variable

Goodnight GamesGoodnight Games NYCMember, PRO Posts: 184
edited April 2012 in Working with GS (Mac)
I have blocks spawning on a timer from an actor at the top of the screen. Every time the timer goes off the block is spawned and the spawnTime variable gets shorter. The is for the spawnTime to decrease over time.

My problem is the spawnTime variable will go down but for some reason it won't apply to the timer unless I get killed and invoke the reset scene function (I haven't put anything in to reset spawnTime after death). Is there any way I can fix this?


I've tried both constrain and change attributes. I've tried having it in a separate actor and running it off a timer to decrease the variable. All of these result in the variable going down but they won't continually update the timer.


My code in the spawner is here: http://25.media.tumblr.com/tumblr_m2sd1u4lbV1r4qsqko1_1280.png

Thanks!

Best Answer

Answers

  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    The time will not get quicker because it'll just do what the attribute is at first. If the attribute is 1 at the start and changes a million times, it will still be set as every 1 second.

    Do you want me to make you a demo?

    Ace
  • Goodnight GamesGoodnight Games NYCMember, PRO Posts: 184
    The time will not get quicker because it'll just do what the attribute is at first. If the attribute is 1 at the start and changes a million times, it will still be set as every 1 second.

    Do you want me to make you a demo?

    Ace

    If you could I would seriously appreciate it, thanks!

  • Goodnight GamesGoodnight Games NYCMember, PRO Posts: 184
    http://www.mynameisace.com/spawnTime.gameproj.zip

    That's I checked it out and let me make sure my logic is correct so you have it when:


    The first part confuses me but I'm assuming you're calling an in game time function that when it's greater than Timer to change the Spawn to 1 (so in other words it'll count to 3 and spawn off the bat).

    Then once it's spawned the game time function cannot be called again because it keeps counting up.

    So the actor is spawned with a timer attached and sets the Spawn to 0 preventing anything new from spawning. When the timer goes off it is subtracted by -.2 and the spawn is set back to one so a new actor is spawned.

    Then that would mean all of my actors have timers embedded in them to change the spawn by .2 so it would decrease every time an actor spawned thus giving me an exponentially decreasing spawn rate.


    I have one last question, the player can destroy the actors by running into them if they're a certain type. Will having them leave the screen early effect the code working and if so how do I fix this?

    Thanks again for all your help.

  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    Exactly, that's what's happening :)

    Yeah, it would affect the code, but there are ways around it.

    Either you could do, when it collides, move the y position to -(self.size.height/2) and after x amount of time it destroys (to cover the fact that it might not have finished it's rules)

    Or, you could tie the time to another actor so there wouldn't be as many timers going off at once... Let me knock up an optimised version for you. Gimme 5 minutes

    Ace
  • Goodnight GamesGoodnight Games NYCMember, PRO Posts: 184
    Here you go:

    http://www.mynameisace.com/spawnTimeOptmise.gameproj.zip

    Optimised it so there aren't a load of timers and that it uses it's self alpha attribute to trigger, so no need for extra attributes bogging the game down.

    Ace
    Thanks again for being so awesome.

    Ok so logic wise:

    The first rule in the spawner checks the game time and sets the spawners alpha to 1 after .2 seconds so it doesn't fire early.

    Once the alpha is set to 1 the spawning rule in the spawner is triggered where it:

    A) Subtracts from the spawn timer
    B) Set the alpha to zero so that it doesn't get set off again
    C) The actor is then spawned
    D) A Timer is started using the spawn timer variable that was just subtracted from and when it finishes it sets the alpha to 1 thus repeated the cycle.

    I think I've got it!

Sign In or Register to comment.