09-22-2016, 01:12 AM
Hello everyone. I am at work on a mod that will feature an in-game clock. The goal is to have the time be visible throughout the entire mod. The timer works in the first map. However, I have experienced some issues when transfering the values from one map to another. I have attached an image of the errors received.
Error Message
I have also included the code as well. (Note that I will start it at line 36 in 02_Cellar.map.)
Code: 01_House.map (OnLeave only)
Code: 02_Cellar.map
I have tried everything from commenting out certain sections of code, moving variables around, conversions, and making sure spelling is correct. No positive results have shown. It seems that it may have something to do with the global variables. However, I do not know why they are not working. If anyone could provide some insight as to what the issue is, that would be greatly appreciated.
Many thanks!!
Error Message
I have also included the code as well. (Note that I will start it at line 36 in 02_Cellar.map.)
Code: 01_House.map (OnLeave only)
PHP Code:
void OnLeave()
{
AddTimer("Stop", 0.1f, "MasterTimer");
SetGlobalVarInt("Hours", gameHours);
SetGlobalVarInt("Minutes", gameMinutes);
SetGlobalVarFloat("TimeScale", timeScale);
}
Code: 02_Cellar.map
PHP Code:
int gameHours = GetGlobalVarInt("Hours");
int gameMinutes = GetGlobalVarInt("Minutes");
float timeScale = GetGlobalVarFloat("TimeScale");
void MasterTimer(string &in asTimer)
{
if(asTimer == "Stop")
{
RemoveTimer("Tick");
}
else if(asTimer == "Initialize")
{
ChangeTime(gameHours, gameMinutes,"Set");
AddTimer("Tick", timeScale, "MasterTimer");
}
else if(asTimer == "Tick")
{
ChangeTime(0,1,"Add");
AddTimer("Tick", timeScale, "MasterTimer");
}
SetMessage("TimeValues", "" + gameHours + ":" + gameMinutes, 0.0f);
}
void ChangeTime(int hours, int minutes, string changeMode)
{
if(changeMode == "Add")
{
gameHours += hours;
gameMinutes += minutes;
// Add hours till minutes are less than 60
while(gameMinutes > 59)
{
gameHours++;
gameMinutes -= 60;
}
}
else if(changeMode == "Set")
{
gameHours = MathClamp(hours, 0, 23);
gameMinutes = MathClamp(minutes, 0, 59);
}
// Support Outside Function
// Does any time-update commands.
OnTimeUpdate();
}
void OnEnter()
{
PlaySoundAtEntity("cellarambience", "13_amb.snt", "Player", 1.0f, false);
AddTimer("Initialize", 2.0f, "MasterTimer");
}
void OnLeave()
{
StopSound("cellarambience", 1.0f);
AddTimer("Stop", 0.1, "MasterTimer");
}
I have tried everything from commenting out certain sections of code, moving variables around, conversions, and making sure spelling is correct. No positive results have shown. It seems that it may have something to do with the global variables. However, I do not know why they are not working. If anyone could provide some insight as to what the issue is, that would be greatly appreciated.
Many thanks!!