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


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tracking playing time
Akasu Offline
Member

Posts: 62
Threads: 6
Joined: Aug 2010
Reputation: 2
#1
Tracking playing time

I was wondering if there is a smart way to track the time someone has played a certain custom story and display it when the player interacts with, for example, a clock entity in game.

The tracking could probably happen like this:
void OnStart()
{
AddGlobalVarInt("time", 0);
AddTimer("timer", 60, "tracker");
}

void tracker (string& asName)
{
SetGlobalVarInt("time", GetGlobalVarInt("time")+1; // don't know if it works like this. gotta test
AddTimer("timer", 60, "tracker");
}

This would track the game time every minute but the problem is how to display it... One way to do this is trough a debug message:
AddDebugMessage("Time played: "+GetGlobalVarInt("time"), false);
but the player would need to have debug mode on for it to show.

If it was done trough SetMessage I'd need to make lots of entries in the lang file which would be pretty time consuming.
So what would be the smartest way to do this?
08-09-2011, 04:28 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Tracking playing time

I know the .lang file supports calling commands by using the $ character. However, i haven't done anything with it, so i'm not sure how it works.

Tutorials: From Noob to Pro
08-09-2011, 04:40 PM
Website Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#3
RE: Tracking playing time

As far as I am aware, the $ sign is only used for variables relating to keys. It isn't too hard to generate some code that will create some entries automatically for you though, so the brute force approach isn't off the table at all here; I've hastily slapped the following together in python to prove the point:
# --- Initial Setup --- #
#File name
fname = "output1.txt"
#Lang File details
lfCatagory = "gametime" #The catagory of the time entries
lfPfx = "gt"            #Prefix of each entry
#Message String
msPrefix = "You have played for" #Prefix of the entry
msSuffix = "in this session"     #Suffix of the entry
#Limits
lmLower = 1    #Smallest possible time spent playing (mins)
lmUpper = 6001 #Upper bound on time spent playing (mins)
#Mode      #1: HH hours MM minutes
mode = 1   #2: HH:MM
          
# --- Precalculation --- #
lfPfx = "    <Entry Name=\"" + lfPfx
msPrefix = "\">" + msPrefix
msSuffix = " " + msSuffix + "</Entry>\n"

# --- Generation --- #
#Catagory line
output = "  <CATEGORY Name=\"" + lfCatagory + "\">\n"

     #Generate entries (mode 1)
if mode == 1:
    for m in range(lmLower,lmUpper):
        ihrs = m / 60
        imns = m % 60
        hrs = ""
        mns = ""
        if ihrs > 0:
            hrs = " " + `ihrs` + " hour"
            if ihrs != 1:
                hrs += "s"
        if imns > 0:
            mns = " " + `imns` + " minute"
            if imns != 1:
                mns += "s"
        output += lfPfx + `m` + msPrefix + hrs + mns + msSuffix
else: #Generate entries (mode 2)
    for m in range(lmLower,lmUpper):
        ihrs = m / 60
        imns = m % 60
        output += lfPfx + `m` + msPrefix + " " + `ihrs` + ":" + `imns` + msSuffix
#Add in closing catagory tag
output += "  </CATEGORY>"


# --- Write the output --- #
try:
    fout = open(fname,"w")
    fout.write(output)
    fout.close()
except IOError:
    print "Error writing to file!"

This will generate all the entries up to 100 hours of playtime. You can change the initial settings and stuff to suit. Just copy-paste the output into the relevant spot in the relevant lang file. I generated a file of approx 524kb using this script, entries looking like:
<Entry Name="gt2">You have played for 2 minutes in this session</Entry>
  <Entry Name="gt3">You have played for 3 minutes in this session</Entry>
  <Entry Name="gt4">You have played for 4 minutes in this session</Entry>
  <Entry Name="gt5">You have played for 5 minutes in this session</Entry>
  <Entry Name="gt6">You have played for 6 minutes in this session</Entry>
  <Entry Name="gt7">You have played for 7 minutes in this session</Entry>
  <Entry Name="gt8">You have played for 8 minutes in this session</Entry>
...
  <Entry Name="gt5996">You have played for 99 hours 56 minutes in this session</Entry>
  <Entry Name="gt5997">You have played for 99 hours 57 minutes in this session</Entry>
  <Entry Name="gt5998">You have played for 99 hours 58 minutes in this session</Entry>
  <Entry Name="gt5999">You have played for 99 hours 59 minutes in this session</Entry>
  <Entry Name="gt6000">You have played for 100 hours in this session</Entry>
You can then use the entries as follows:
void OnStart()
{
SetGlobalVarInt("time", 1); //Init time var
AddTimer("timer", 2* 60, "tracker"); //Not really bothered with 0th minute.
}

void tracker(string& asName)
{
AddGlobalVarInt("time",1); //Increment time var
AddTimer("timer", 60, "tracker"); //Increment again in 1 min
}

void showTime()
{
//It's show time, for showing the time.
//*badum* *tish*
SetMessage("gametime","gt"+GetGlobalVarInt("time"),-1);
}
This is very much a inelegant approach, but 500kb is nothing - it is like adding 1 custom decal, and you can probably relax the time constraint down to under half the size of that. It would be nice if there was a virtual "temp" entry, that we could read/write to using scripting, and then use as if it was in the language file though!

This method assumes you want to track the total time the player spent playing the game. Obviously, if you want it to tell the time based on how long the player has been playing you would take a similar approach but have a greatly decreased time interval, as only 24 hours would need to be covered and the modulo function would handle the rest.
(This post was last modified: 08-09-2011, 09:37 PM by Apjjm.)
08-09-2011, 06:21 PM
Find
Phoroneus Offline
Member

Posts: 141
Threads: 12
Joined: Feb 2011
Reputation: 0
#4
RE: Tracking playing time

If you want to go purely by scripts, you could theoretically set a 60-second timer that refreshes itself and increments a variable (e.g. "ClockTime"). Then, when you interact with the clock it could call for the variable to determine what time to display. This might end up becoming a really long script though, unless you managed to get the display time right from the variable instead of running it through extra_english.lang, since you'd need 60 minutes (times roughly two lines) per hour, and at least twelve if not twenty-four hours' worth of minutes to display the time via extra_english.

If you wanted to be really devious, you could set one timer to increment a variable (i.e. "ClockMinutes") for 0-59 and then reset, incrementing a second variable (i.e. "ClockHours") and setting "ClockMinutes" to zero. Once "ClockHours" reached 12 (or 24) it could also reset back to zero, effectively creating a clock out of .hps script.

Of course, how you'd implement the clock in a recognizable fashion into the game is another matter.

[Image: at_9365860.png]

Follow Harvest.
08-09-2011, 08:08 PM
Find




Users browsing this thread: 1 Guest(s)