Script for getting the system clock's value?
by Orion the Hunter · in Torque Game Builder · 07/09/2013 (6:19 am) · 9 replies
Is there a function that TGB comes with that returns the current time? I'm working on a level where the environment changes depending on the current time of day. I think I read some stuff about T3D having something of that nature but I didn't see anything for T2D. If there isn't a stock function, has anyone implemented it before? By the way, I do have the source on hand.
Thanks!
Thanks!
#2
07/09/2013 (3:45 pm)
I tried it but it says it can't find the function... :(
#3
As a suggestion, look in console/consoleFunctions.cc. You could probably use something like getPrefsPath as a template to make a new function to return the time from the c++ layer to the scripting layer.
07/09/2013 (4:49 pm)
I took a quick look through and didn't see anything obviously in the current code that would let you call it from the script (though I may have missed something!) It should be a pretty easy addition to code though. As a suggestion, look in console/consoleFunctions.cc. You could probably use something like getPrefsPath as a template to make a new function to return the time from the c++ layer to the scripting layer.
#4
Rebuild, copy your game exe to your game folder....
07/09/2013 (7:27 pm)
Just drop it in source/platform/platform.cc at the end - from T2D MIT....ConsoleFunction( getLocalTime, const char*, 1, 1, "() Get the local timen"
"@return the local time formatted as: monthday/month/year hour/minute/secondn")
{
char* buf = Con::getReturnBuffer(128);
Platform::LocalTime lt;
Platform::getLocalTime(lt);
dSprintf(buf, 128, "%d/%d/%d %02d:%02d:%02d",
lt.monthday,
lt.month + 1,
lt.year + 1900,
lt.hour,
lt.min,
lt.sec);
return buf;
}Rebuild, copy your game exe to your game folder....
#5
07/12/2013 (10:51 am)
Huh... I did everything you told me to and built it as well but it doesn't seem to recognize it as a function. I didn't get any errors when building the game, which is weird...
#6
07/12/2013 (2:48 pm)
Did you copy the new game exe to your project folder? It should be located in <your TGB install folder>/tgb/gameData/T2DProject, named TGBGame.exe (or TGBGame_Debug.exe for the debug build). T2D's build system does not automatically place the finished executable in your game project folders for you.
#7
07/14/2013 (5:21 pm)
I did, and it doesn't seem to want to budge. GetRealTime, however, does do something interesting but alas, it isn't what I was aiming for. getRealtime( will return the current milliseconds on the clock, and I think getLocalTime is what I need. Interestingly enough, when I searched for getRealTime, I found it in platform_scriptBinding.h and not only that, but your function had nested itself there, too. Weird, right? My theory is there is some missing component for getLocalTime.
#8
07/16/2013 (8:13 am)
Nice theory, might have something to do with the platform code for Mac. The code above works on Windows - tested it with 1.7.5, 1.7.6 and 1.8 - but I don't have a Mac and don't plan to have one for the forseeable future.
#9
07/19/2013 (4:35 pm)
Ah, darn it! I hate it when I run into walls like that. I guess I'll have to work around that as I am planning on releasing my game on Windows as well as Mac... Real bummer, that.
Torque Owner Richard Ranft
Roostertail Games