Ok soo this one is a bit complicated...
I have a time system working in the game (using Orange Time System by Hudell).
The time system doesn't use real time and is more like a counter that counts seconds, minutes, etc.
I use this to determine when to give the player a life. (Similar to basically every phone game lol, ex. candy crush, pokemon shuffle, etc.)
Sooo I've got it all working perfect while the game is running, however I am now attempting to determine the lives gained while the game is off.
My current situation is this:
I auto-save the game ever time a map is loaded (ideally would also like to save when the game exits... WIP)
The save stores the "getTime" from the date object into a game variable.
(number in milliseconds since midnight of January 1, 1970)
Reference found here: http://www.w3schools.com/jsref/jsref_gettime.asp
When the game is loaded it checks for saves and loads the auto-save if there is.
Then I run a function to calculate how many lives should be given.
Currently I do attempt this by comparing the oldTimeVariable with the current time. (again in milliseconds)
I can basically get how many lives should be earned by the following:
However I have a serious problem with that... I need to remove what has passed from the time variables and determine whether or not they have earned lives. Sooo I've kind of hit a wall & need help.
This is the function mentioned (although I've altered it to many times to even make much since of it myself now lol):
Summary:
I need to have time pass when the game is off to gain lives.
Most likely this will have to be simulated since the game is completely off.
Thank you for reading.
I hope someone can help me.
I have a time system working in the game (using Orange Time System by Hudell).
The time system doesn't use real time and is more like a counter that counts seconds, minutes, etc.
I use this to determine when to give the player a life. (Similar to basically every phone game lol, ex. candy crush, pokemon shuffle, etc.)
Sooo I've got it all working perfect while the game is running, however I am now attempting to determine the lives gained while the game is off.
My current situation is this:
I auto-save the game ever time a map is loaded (ideally would also like to save when the game exits... WIP)
The save stores the "getTime" from the date object into a game variable.
(number in milliseconds since midnight of January 1, 1970)
Reference found here: http://www.w3schools.com/jsref/jsref_gettime.asp
When the game is loaded it checks for saves and loads the auto-save if there is.
Then I run a function to calculate how many lives should be given.
Currently I do attempt this by comparing the oldTimeVariable with the current time. (again in milliseconds)
I can basically get how many lives should be earned by the following:
JavaScript:
var oldMinutes = (oldMilliseconds / 1000) / 60;
var newMinutes = (newMilliseconds / 1000) / 60;
livesGained = Math.floor((newMinutes - oldMinutes)/minutesBeforeNewLife);
This is the function mentioned (although I've altered it to many times to even make much since of it myself now lol):
JavaScript:
var calculateAddedHearts = function(){
// $gameVariables.setValue(21, $gameVariables.value(23));
if ($gameVariables.value(21) < $gameVariables.value(23)){
var oldTime = $gameVariables.value(151);
var dateObj = new Date();
var oldMilliseconds = oldTime;
var newMilliseconds = dateObj.getTime();
var millisecondsLeftOnClockWhenSaved = (((($gameVariables.value(22)-1)-$gameVariables.value(2))*60)+(60-$gameVariables.value(1)))*1000
if ((newMilliseconds-oldMilliseconds) > millisecondsLeftOnClockWhenSaved){
newMilliseconds = newMilliseconds - millisecondsLeftOnClockWhenSaved;
$gameVariables.setValue(1, 0);
$gameVariables.setValue(2, 0);
var oldMinutes = (oldMilliseconds / 1000) / 60;
var newMinutes = (newMilliseconds / 1000) / 60;
if (($gameVariables.value(21) + Math.floor(((newMinutes - oldMinutes)/5))) < $gameVariables.value(23)){
$gameVariables.setValue(21, $gameVariables.value(21) + (newMinutes - oldMinutes));
}else{
$gameVariables.setValue(21, $gameVariables.value(23));
}
}else{
millisecondsLeftOnClockWhenSaved = millisecondsLeftOnClockWhenSaved - (newMilliseconds-oldMilliseconds);
if ((millisecondsLeftOnClockWhenSaved*1000) > 60){
var minutesAfterLoaded = (millisecondsLeftOnClockWhenSaved*1000) / 60;
var secondsAfterLoaded = (millisecondsLeftOnClockWhenSaved*1000) % 60;
$gameVariables.setValue(1, secondsAfterLoaded);
$gameVariables.setValue(2, minutesAfterLoaded);
}
}
console.log("Lives Gained: " + Math.floor((newMinutes - oldMinutes)/5));
console.log("Minutes Passed: " + Math.floor(newMinutes - oldMinutes));
}
}
Summary:
I need to have time pass when the game is off to gain lives.
Most likely this will have to be simulated since the game is completely off.
Thank you for reading.
