Previous Blog Next Blog
Prev/Next Blog
by date

Temp Resource: Script Time

Temp Resource: Script Time
Name:Richard_H 
Date Posted:Nov 09, 2006
Rating:Not Rated
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Richard_H

Blog post
Due to slow resource aproval I'm posting my resource here so I can get some feedback and spread the little C++ knowledge.

A simple way to add a console function ( getSysTime() ) for getting the time in seconds since midnight from the system clock. Note: This is my first resource and is kind of basic.

1. First you need to add the time header file (<time.h>),
open up main.cc and go to the end of the #includes and add

#include <time.h>


2. Next we need to actualy add the console function,
go down past the 2 existing time functions

ConsoleFunction( getSimTime, S32, 1, 1, "Return the current sim time in milliseconds.\n\n"
"Sim time is time since the game started.")
{
return Sim::getCurrentTime();
}

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();
}

and add

ConsoleFunction( getSysTime, int, 1, 1, "Get the time in seconds.")
{
time_t rawtime;
struct tm * timeinfo;
int temp;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
temp = timeinfo->tm_sec;
temp = temp + (timeinfo->tm_min*60);
temp = temp + (timeinfo->tm_hour*3600);
return temp;
}

Basicly, what this does is get a tm struct and convert the hours and minutes to seconds,
then add them to the seconds then return the result.

To test if it worked just type the following in the console:

echo(getSysTime());

You should get the number of seconds since midnight.
Please comment so I can make my next resource better.

Recent Blog Posts
List:09/15/07 - Redesigned Website
07/04/07 - AI Wars
06/21/07 - Random Mission Pack:Done!
05/30/07 - Random Mission Pack:It's not dead!
03/14/07 - Random Mission Pack:Road Update
02/24/07 - Random Mission Pack
11/29/06 - New Game
11/09/06 - Temp Resource: Script Time

Submit ResourceSubmit your own resources!

Tom Bentz   (Nov 09, 2006 at 04:22 GMT)
Very nice... I was actually curious how to do a simple console function implementation myself. This will really help! THANKS!

You must be a member and be logged in to either append comments or rate this resource.