Last active
December 15, 2015 17:59
-
-
Save deanPGM/5300709 to your computer and use it in GitHub Desktop.
Daily Bonus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- For info go to the following web address: | |
-- https://developer.coronalabs.com/code/daily-bonus | |
prefs = require "preference_library" | |
local function checkForSinglePlayerBonus( ) | |
local lastDayNum = prefs.getValue( "lastDayNum" ) or 0 | |
local lastMonthNum = prefs.getValue( "lastMonthNum" ) or 0 | |
local date = os.date( "*t" ) | |
local thisDayNum = (date.day) | |
local thisMonthNum = (date.month) | |
if thisDayNum == lastDayNum then | |
if thisMonthNum ~= lastMonthNum | |
-- same day, different month! | |
bonusIndex = 1 | |
end | |
else | |
if thisDayNum == lastDayNum+1 then | |
-- increase the bonus | |
bonusIndex = bonusIndex + 1 | |
if bonusIndex == 6 then | |
bonusIndex = 1 | |
end | |
else | |
-- more than a day since the last session, reset the daily bonus | |
bonusIndex = 1 | |
end | |
end | |
prefs.save( "bonusIndex", bonusIndex ) | |
prefs.save("lastDayNum", thisDayNum) | |
prefs.save("lastMonthNum", thisMonthNum) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Missing a "then" at the end of line 13.