Counter with different targets

MarcoColMarcoCol Member, PRO Posts: 279

Hi,

in my game I want to add a counter. Based on the difficulty, the timer should have different time-targets.
For example, the counter time can be 1, 2, 3, 5 or 10 minutes.
The timer should rund vom the target to 0 or from 0 to the target.
The format of the timer should be mm:ss

I've tried to make with with timers and change attributes. That work, but it's a lot of work and a lot of calculations and I've read before, the each timer takes a lot of work in the game and it's better to use less timers than more.

Does anyone can help me, to bring me on the right direction?

Thanks.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    How many timers are you planning on using? If you only have a single countdown or count-up timer, you should be fine. The OSTime Demo is a good place to start: https://gamesalad.com/support/manuals.

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

  • pHghostpHghost London, UKMember Posts: 2,342

    Not using too many timers is mostly an outdated suggestion. GameSalad can deal with timers much better than some old versions and also the performance of smartphones has gone up radically in the same time. If this is the only major use of a timer in your app, it will not cause any problems.

    You say it is a lot of work and calculations -- shouldn't be. Can you share with us the mouthed you used? Ideally screenshots of the logic.

    One important question though -- with the timer, are you in-app all the time, or with the 10 minute timer, can you exit the app, come back 5 minutes later and continue with 5 minutes on the timer?

  • MarcoColMarcoCol Member, PRO Posts: 279
    edited October 2017

    It should be displayed only one counter at one time.

    The user should have the option to reset it, to start/stop it (by tapping on it) and to select another length (if so, the counter will be reset to the full value automatically).
    If the user leave the app, it should be reset or pause. There's no need for going on in the background.


    Currently I made some attributes (integer):

    • clock-is-running (0) (0=no, 1=yes)
    • clock (0) - (will be set which length the user select, 0= 1min, 1=2min, 2=3 min...)
    • time-min (0) (will show the minutes on the counter)
    • time-sec (0) (will show the seconds on the counter)

    So I made to actors:
    clock-calculations

    rule
    when attribute clock=0
    change attribute=time-min to 1
    change attribute=time-sec to 0

    rule (all)
    when attribute=clock-is-running=1
    when attribute=time-sec >=0
    after 1 seconds
    change attribute=time-min to 0
    change attribute=time-sec to 59
    every 1 seconds
    constrain attribute=time-sec to 0

    clock-display

    display text: time-min (=> 15px)
    display text: ":" (=> 30px)
    display text: time-sec (=> 50px)

    rule if touch is pressed
    change attribute=clock-is-running to (clock-is-running+1)%2


    Maybe it's not the best and not beautiful. Also the minutes/seconds will not be displayed like an original clock (alignment). But it should work (but it doesn't work) :( )

    Regards

  • pHghostpHghost London, UKMember Posts: 2,342

    Try this: https://www.dropbox.com/s/a9cmkunwh9vwclg/Basic Timer.zip

    Just two game attributes (plus an actor attribute) and relatively straightforward logic. Ask any questions if you have them.

  • MarcoColMarcoCol Member, PRO Posts: 279

    Oh, wow, well, much easiert. That's brillant. I chance a bit to optimize it for my project, but it works perfect.
    Thanks a lot

  • pHghostpHghost London, UKMember Posts: 2,342

    Of course, use it, optimise it and adapt it for your own project. It's just a sample of the basic functionality.

Sign In or Register to comment.