GameSalad

Howdy, Stranger!

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

save and load device time

lotte205lotte205 Tallinn, EstoniaPosts: 41Member, PRO

I want to give the player 10 coins every 24 hours. I don't want it to reset, just keeping adding the 10 coins every day. How can I save the current device time? And how to compare it when the player opens the app. And when the 24 hours passes when the app is open, then how does it add the coins when it already loaded the attribute? I found templates, but they are too complicated and I don't know which ones are currently working. Please help me.

Comments

  • Thunder_ChildThunder_Child Posts: 2,343Member

    Something in my memoery tells me @jamie_c has a good technique for this. It has to do with saving ".game.time" attribute and comparing it to a new time and if ewual or greater than last "game.time" allow coins and save NEW game.time. It sounds complicated...and is probably much easier for others with much more experience...once you get it I bet it becomes a simple task to include in your games.

  • RabidParrotRabidParrot Formally RabidParrot. Posts: 956Member
    edited November 2015

    I've taken the date and converted it to a single number. I then saved the value and compared it to the current day. If the current day has a greater value than the saved day then I reward the user.

    I do something like this, 20151129. That's the year 2015 the month 11 the day 29.

    You can add the hour to check if it has been 24 hours. The logic is very simple it's the math you have to work with

    20151129 is less than 20151130.

    It works with month also.

    20151129 is less than 20151230

    20151215 is less than 20160105

    I'm sure this just looks like a bunch of gibberish.

  • lotte205lotte205 Tallinn, EstoniaPosts: 41Member, PRO

    @Thunder_Child Thank you.

    @RabidParrot It's not gibberish :) But how do you add them, it can't work when you just add 2015+11+29

  • RabidParrotRabidParrot Formally RabidParrot. Posts: 956Member
    edited November 2015

    @lotte205 said:
    @Thunder_Child Thank you.

    @RabidParrot It's not gibberish :) But how do you add them, it can't work when you just add 2015+11+29

    to get 20151129

    (Year x 10000)+(Month x 100)+Day= Time

    (2015 x 10000)+(11 x 100)+29=20151129

  • RThurmanRThurman Posts: 2,820Member, Sous Chef, PRO

    @RabidParrot -- Great idea for making a fixed date!

    But won't it mess up when the month or the day is a single digit. It would probably be better to use padInt() to pad the month and day with a leading '0' when necessary.

    Also, you can concatenate numbers together (like it was a string) with two dots (..). GameSalad (via Lua) will allow strings to be converted to numbers -- when it can.

    So your timestamp could also be built with the following expression:
    game.Clock.Year..padInt( game.Clock.Month,2)..padInt( game.Clock.Day,2)

  • RabidParrotRabidParrot Formally RabidParrot. Posts: 956Member
    edited November 2015

    @RThurman said:
    @RabidParrot -- Great idea for making a fixed date!

    But won't it mess up when the month or the day is a single digit. It would probably be better to use padInt() to pad the month and day with a leading '0' when necessary.

    Also, you can concatenate numbers together (like it was a string) with two dots (..). GameSalad (via Lua) will allow strings to be converted to numbers -- when it can.

    So your timestamp could also be built with the following expression:
    game.Clock.Year..padInt( game.Clock.Month,2)..padInt( game.Clock.Day,2)

    You shouldn't have an issue with a single digit day because the day and month are already defined as a value *10^x

    For instance,

    (2015 x 10000)+(12 x 100)+01= 20151201

    (2015x10000)+(01x100)+01= 20150101

  • RThurmanRThurman Posts: 2,820Member, Sous Chef, PRO

    You are exactly right!
    Thats a crafty little trick you have created there!

    (I should have checked first before I assumed it would mess up with a single digit month.) :)

  • HopscotchHopscotch Posts: 2,782Member, PRO

    @lotte205

    may I also suggest our free back-end service for offline timers.

    It solves your requirements, and also adds the security that a user does not set the clock forward by a month and instantly gains 300 coins.

    Link to the website is in the signature.

    @Braydon_SFX also presented this in detail at the last GS meetup here : http://forums.gamesalad.com/discussion/90489/monthly-gamesalad-meetup-thursday-january-7-2016-at-7pm-cst-01-00-gmt#latest

    The video to the meetup is found here : www.youtube.com/watch?v=OxK0vo3jNHU

Sign In or Register to comment.