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
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


Messages In This Thread
Tracking playing time - by Akasu - 08-09-2011, 04:28 PM
RE: Tracking playing time - by Your Computer - 08-09-2011, 04:40 PM
RE: Tracking playing time - by Apjjm - 08-09-2011, 06:21 PM
RE: Tracking playing time - by Phoroneus - 08-09-2011, 08:08 PM



Users browsing this thread: 1 Guest(s)