Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] In-game clock not working
DanielRand47 Away
Member

Posts: 109
Threads: 16
Joined: Mar 2012
Reputation: 3
#1
[SOLVED] In-game clock not working

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
[Image: nwh6vUM.png]

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: (Select All)
void OnLeave()
{
    
AddTimer("Stop"0.1f"MasterTimer");

    
SetGlobalVarInt("Hours"gameHours);
    
SetGlobalVarInt("Minutes"gameMinutes);
    
SetGlobalVarFloat("TimeScale"timeScale);


Code: 02_Cellar.map
PHP Code: (Select All)
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(gameHoursgameMinutes,"Set");
        
AddTimer("Tick"timeScale"MasterTimer");
    }
    else if(
asTimer == "Tick")
    {
        
ChangeTime(0,1,"Add");
        
AddTimer("Tick"timeScale"MasterTimer");
    }

    
SetMessage("TimeValues""" gameHours ":" gameMinutes0.0f);
}

void ChangeTime(int hoursint minutesstring 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(hours023);
        
gameMinutes MathClamp(minutes059);
    }
    
    
// Support Outside Function
    // Does any time-update commands.
    
OnTimeUpdate();
}

void OnEnter()
{
    
PlaySoundAtEntity("cellarambience""13_amb.snt""Player"1.0ffalse);
    
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!!
(This post was last modified: 09-22-2016, 05:01 PM by DanielRand47.)
09-22-2016, 01:12 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: In-game clock not working

Try putting your Global Vars into a file called global.hps in your /maps directory, with this code.

PHP Code: (Select All)
void OnGameStart()
{
    
SetGlobalVarInt("Hours"gameHours);
    
SetGlobalVarInt("Minutes"gameMinutes);
    
SetGlobalVarFloat("TimeScale"timeScale);


Then remove the SetGlobalVars in your OnLeave();.

You should also start a new game when testing this, since OnGameStart() is only called when you click "New Game" from the menu.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 09-22-2016, 03:23 AM by Romulator.)
09-22-2016, 03:23 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#3
RE: In-game clock not working

One thing you can try is to

PHP Code: (Select All)
int gameHours;
int gameMinutes;
float timeScale;

void OnEnter() {
    
gameHours GetGlobalVarInt("Hours");
    
gameMinutes GetGlobalVarInt("Minutes");
    
timeScale GetGlobalVarInt("TimeScale");


Perhaps that will fix, if not all but some of the problems.

Another thing is I don't think timers run across maps, so your "Stop" timer from OnLeave might not run in the second map, but rather wait until you return to the original map. Not 100% sure here though.

09-22-2016, 03:28 AM
Find
DanielRand47 Away
Member

Posts: 109
Threads: 16
Joined: Mar 2012
Reputation: 3
#4
RE: In-game clock not working

(09-22-2016, 03:23 AM)Romulator Wrote: Try putting your Global Vars into a file called global.hps in your /maps directory, with this code.

PHP Code: (Select All)
void OnGameStart()
{
    
SetGlobalVarInt("Hours"gameHours);
    
SetGlobalVarInt("Minutes"gameMinutes);
    
SetGlobalVarFloat("TimeScale"timeScale);


Then remove the SetGlobalVars in your OnLeave();.

You should also start a new game when testing this, since OnGameStart() is only called when you click "New Game" from the menu.

Alright thanks. I'll do that!

(09-22-2016, 03:28 AM)Mudbill Wrote: One thing you can try is to

PHP Code: (Select All)
int gameHours;
int gameMinutes;
float timeScale;

void OnEnter() {
    
gameHours GetGlobalVarInt("Hours");
    
gameMinutes GetGlobalVarInt("Minutes");
    
timeScale GetGlobalVarInt("TimeScale");


Perhaps that will fix, if not all but some of the problems.

Another thing is I don't think timers run across maps, so your "Stop" timer from OnLeave might not run in the second map, but rather wait until you return to the original map. Not 100% sure here though.

Your solution works! Thanks for this advice! Now to do as Romulator suggested and put them into a global.hps file.
(This post was last modified: 09-22-2016, 03:46 AM by DanielRand47.)
09-22-2016, 03:45 AM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#5
RE: [SOLVED] In-game clock not working

Thanks for using my scripts... Although, I'll create a multiple map support soon. =D
09-23-2016, 11:37 AM
Find
DanielRand47 Away
Member

Posts: 109
Threads: 16
Joined: Mar 2012
Reputation: 3
#6
RE: [SOLVED] In-game clock not working

(09-23-2016, 11:37 AM)Spelos Wrote: Thanks for using my scripts... Although, I'll create a multiple map support soon. =D

That would be awsome man! Something that will make transfering the hours and minutes easier to use. Right now I am having to store them in the GlobalVarInt/Float function, declare and reinitialize the variables that are global to the script file and then update the GlobalVarInt/Float function when I leave the map. Tedious but it does the job. I will say I hope more mods use this time mechanic.
09-23-2016, 05:31 PM
Find




Users browsing this thread: 2 Guest(s)