Game Development Community

Time/Date from script

by Greco Van der Ven · in Torque Game Engine · 05/22/2005 (4:53 pm) · 9 replies

Hi,

I was wondering if anyone knows an easy way to get the date and time from Torquescript.

I have one made by someone else that uses the banlist to do it: It basically bans a non-existent player, exports the banlist, opens that file and reads until it gets to the last number, which is the number of seconds since 1970... Really inventive, but also really weird.

There's gotta be an easier way to do this, right?

About the author

Recent Threads

  • Slow?

  • #1
    05/22/2005 (5:30 pm)
    You could write a consolefunction to get it from the usual time() functions... Pretty sure there isn't one such built in. The getCurrentTime() function is usually enough, it returns time since the server started.
    #2
    05/23/2005 (6:40 am)
    Put this in /engine/game/Main.cc, around line 274, after:

    ConsoleFunction( getRealTime, S32, 1, 1, "Return the current real time in milliseconds.\n\n"
                    "Real time is platform defined; typically time since the computer booted.")
    {
       return Platform::getRealMilliseconds();
    }


    // get date and time --drew
    ConsoleFunction( getLocalTime, const char *, 1, 1, "Return the current local time as: month day year hour min sec.\n\n"
                    "Local time is platform defined.")
    {
    	Platform::LocalTime lt;
        Platform::getLocalTime(lt);
    
    	char *retBuffer = Con::getReturnBuffer(128);
        dSprintf(retBuffer, 128, "%d %d %d %02d %02d %02d",
            lt.month + 1,
            lt.monthday,
            lt.year + 1900,
            lt.hour,
            lt.min,
            lt.sec);
    
       return retBuffer;
    }

    Then in script, you can call something like this:
    %t= getLocalTime();
    echo ("The time-  month:" @ getWord (%t, 0) @ ", day: " @ getWord (%t, 1) @ ", year: " @ getWord (%t, 2) @ ", hour: " @ getWord (%t, 3) @ ", min: " @ getWord (%t, 4) @ ", sec: " @ getWord (%t, 5));
    #3
    05/23/2005 (7:09 am)
    Thanks for the help, but I'm scripting in a precompiled game. I don't have access to the source code.

    I guess there is no function readily available to do what I would like to do, apart from using a weird detour like with the banlist thing.
    #4
    05/23/2005 (11:37 am)
    It's true. Without modifying the code your options become severely limited. :(
    #5
    05/24/2005 (5:15 am)
    I'm looking for the same functionality, and thankfully I can modify the code, so thank you for the answer for me. Sorry for Greco though.
    #6
    05/24/2005 (6:42 am)
    Try to use GuiClock, it can be adedd from gui editor. I think it uses system time. At least you will get a time.
    #7
    05/24/2005 (9:58 pm)
    If you're using networking you can get the current time from a global timeserver using TCPObject.

    TCPObject Tutorial

    Part 2 of the tutorial will be what will interest you.
    #8
    02/10/2007 (9:16 pm)
    Holy Crap Harold, that article is awesome! Oh the internet messages I will send! This kind of stuff is what makes TGE such a wonderful engine, full of crap you never knew you needed! Absolutely awesome!
    #9
    08/14/2009 (8:27 pm)
    Gracias por la respuesta me ha sido de gran utilidad y obviamente resolvió mi problema