Level Timer issue

MelodyCatsMelodyCats Member, PRO Posts: 128

Hi,
Ever since creator 1.24 and now 1.25 I seem to be having trouble with my level timer.
I've got - Timer:
Every 0.1 seconds
Change Attribute: game.LevelTimer to: game.LevelTimer+0.1

For some reason I think the timer is increasing slightly slower than every 0.1 sec so my timer gets gradually more out of sync as the level progresses. As my app is a music rhythm game is really critical for the timing to be right on.

I've had the app out for 3+ years and not come across this with all version pre 1.24.

Is there an alternative way I could program the level timer to the way I'm doing it? or some other workaround.

Any ideas would be really appreciated!
Thanks

Comments

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

    @MusicBoutique said:
    I've got - Timer:
    Every 0.1 seconds
    Change Attribute: game.LevelTimer to: game.LevelTimer+0.1

    I've never really understood why people duplicate the game.time attribute and pass it to another attribute, you see this quite a bit on the forums, from what I can see it doesn't achieve anything different from just using game.time ?

    For example, it's like there is a clock on the wall, it shows you the time, when you want to know the time rather than simply looking at the clock you instead have someone look at the clock for you, they then write down what time it is and then you then read what they've written down . . . and I always think . . 'why not just look at the clock, why the need to duplicate it !?'

    Hope that makes sense ! There is an attribute called game.time, at 12.1 seconds it will hold the value, 12.1, you are using this clock (via a Timer behaviour) to generate another attribute, called game.LevelTimer, that at 12.1 seconds will hold the value 12.1 !! In fact this second attribute (game.LevelTimer) relies on the first attribute (game.time) having the identical value for it to work correctly.

    Or to put it another way, if you wanted to use or display the value held in an attribute called game.coins, would you simply use that value or display that value or would you first make another attribute called, for example, game.coinsValue, copy game.coins to game.coinsValue and then display game.coinsValue ?

  • MelodyCatsMelodyCats Member, PRO Posts: 128

    Thanks very much @Socks - what you're saying does make a lot of sense.
    I wouldn't be surprised if the extra (needless) step in my timer is causing trouble.
    I'll look into to this.
    Thanks for your help!

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

    @MusicBoutique said:
    Thanks very much @Socks - what you're saying does make a lot of sense.
    I wouldn't be surprised if the extra (needless) step in my timer is causing trouble.
    I'll look into to this.
    Thanks for your help!

    How you have it set up should work just fine, your logic is correct, so I expect the issue is likely somewhere else in your code . . . . but yeah, I'd personally just use game.time or self.time where you currently use game.LevelTimer.

  • MelodyCatsMelodyCats Member, PRO Posts: 128

    So I'm looking into this. The only problem I can see with using game.time is that the clock will start running as soon as the scene loads, whereas I need the timer to start running once a button is pressed. I can't seem to be able to stop or start game.time when I need to...

    Its quite puzzling though, because as you mentioned I think my logic should be correct - I'm attaching a GS proj as an example.

    If you press the button, the timer will start running. ( Every 0.1 seconds
    Change Attribute: game.LevelTimer to: game.LevelTimer+0.1)

    The thing is the timer is slightly slower than it should be - if you use a stopwatch alongside it after about 30 seconds it will be about 5 seconds behind and the gap keeps growing the longer the timer runs.

    If you display game.time then that does run correctly alongside a stop watch.

    I'm not sure if any of this is making sense!
    Basically the rule (Every 0.1 seconds
    Change Attribute: game.LevelTimer to: game.LevelTimer+0.1) used to work pre 1.23 but doesn't anymore...

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

    @MusicBoutique said:

    So I'm looking into this. The only problem I can see with using game.time is that the clock will start running as soon as the scene loads, whereas I need the timer to start running once a button is pressed. I can't seem to be able to stop or start game.time when I need to...

    Game.time cannot be stopped or restarted, the standard approach is to use an offset . . .

    Personally, when I want a timer that can start, stop, speed up, slow down, go backwards or even oscillate forwards and backs (and so on), I usually throw a small actor into the scene and use its rotation as my timer . . . . simply start it rotating and use its angle as your clock, 1 degree a second would be ideal (so angle = seconds), but unfortunately there's a bug in GS where very slow rotational speeds stop rotating, so I use a value of 100°/sec . . . and of course it's trivial to stop and start something rotating with simple rules, and the 'timer' always picks up from where it left off, so if you stopped it at 5404° (54.04 seconds) - and left in in 'pause' for as long as you need - and then restarted the rotation it would then continue on from where it left off . . 5405°, 5406°, 5407°, 5408° . . . .

    A small (offscreen / invisible) actor controlling the game's timer is much more flexible in those situations where you want to start, stop and reset timers. Example - want to give someone a bonus 15 seconds ? - Simply rotate the controller back 15° (or 1500° if we are using 100°/sec).

  • CodeWizardCodeWizard Inactive, Chef Emeritus Posts: 1,143

    @MusicBoutique One thing to note is that the elapsed time between timers isn't guaranteed to be exactly the amount you set. It's guaranteed to be at least that long. So, it's expected behavior that you'd get some lost time there. I'll see what I can do to address that . But, in the meantime, you can work around that by using game.time.

  • MelodyCatsMelodyCats Member, PRO Posts: 128

    Thanks very much @CodeWizard and for the help on the workaround!

Sign In or Register to comment.