Skip to content

Instantly share code, notes, and snippets.

@deanPGM
Last active December 15, 2015 17:59
Show Gist options
  • Save deanPGM/5300709 to your computer and use it in GitHub Desktop.
Save deanPGM/5300709 to your computer and use it in GitHub Desktop.
Daily Bonus
-- 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
@naveen-pcs
Copy link

Missing a "then" at the end of line 13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment