Tuesday, 17 September 2013

Newbie lua - timed bonus

Newbie lua - timed bonus

I am fairly new to the lua language and I wonder if anyone out there can
help please?
I am making a game in lua - specifically Corona SDK - and I am stuck (and
have been for about a week now) on a timed health bonus ( the player would
get a health bonus every 4 hours) and the second part is the Player would
get a free spin of a wheel type game that will give them the chance to win
free items to use in the game.
The part that is really confusing me is how do I get the timed bonus to be
accurate (ex. every 4 hours and once a day) to fire off the functions for
the bonuses? I also want there to be a count down timer showing
hours:minutes:seconds left before next available bonus can be collected???
Is this impossible to do? Please help me. I am really confused and fairly
new to all of this.
I have searched and tried to find tutorials and example code for about 5
or 6 days now but to no avail.
here is some of my code so far...
function hourlyBonus()
local date = os.date( "*t" )
local currentHour = date.hour
lastHourlyBonusClaimedHour =
GameSave.lastHourlyBonusClaimedHour or date.hour
--account for the 24 hour clock
if currentHour > 12 then
currentHour = currentHour - 12
end
if lastHourlyBonusClaimedHour > 12 then
lastHourlyBonusClaimedHour = lastHourlyBonusClaimedHour - 12
end
if currentHour == (lastHourlyBonusClaimedHour + 4) then
lastHourlyBonusClaimedHour = currentHour
-- increase the bonus
print("New 4 hour bonus ThisHour is:
"..thisHourNum)
else
local hoursToWait = (4 - (currentHour -
lastHourlyBonusClaimedHour))
--have to wait for hourly bonus
print("Have to wait: "..hoursToWait.."hours,
"..minutes.."minutes, and "..second.."seconds
to collect hourly Bonus still!")
print("CurrentHour is:"..currentHour)
print("LastHourlyBonusClaimedHour is
:"..lastHourlyBonusClaimedHour)
end
GameSave.lastHourlyBonusClaimedHour =
lastHourlyBonusClaimedHour
GameSave:save()
end
I am totally lost. If anyone has some sample code I could look at or show
me how to do this I would greatly appreciate it! Thanks for any help in
advance.

No comments:

Post a Comment