XP Per Day Script.

Posted by Shigs on Tue 05 Aug 2008 03:59 PM — 6 posts, 20,648 views.

#0
I'm trying to make pull a script togther to report the xp I make per day.

Here is my code


xp_gained = xp_gained or {}  -- make xp_gained table
day = os.date ("%A, %m %B %Y") -- Get todays date.
xp = %1  -- the xp gained (first wildcard)

-- add day entry if first day

xp_gained [day] = xp_gained [day] or { xp = 0 }
-- add xp to the days xp, 

xp_gained [day].xp = xp_gained[day].xp + xp



%1 is set by the trigger.
You got * xp.

Unfortunatly on the trigger matching, I get...


Quote:

Run-time error
World: nw
Immediate execution
[string "Trigger: "]:11: attempt to perform arithmetic on field 'xp' (a nil value)
stack traceback:
[string "Trigger: "]:11: in main chunk


Any ideas why.. I don't understand why xp is returning nil, when its being set by the trigger.
#1
Code Ammended.
Bug still persists.


xp_gained = xp_gained or {}  -- make xp_gained table
day = os.date ("%A, %m %B %Y") -- Get todays date.
xp = %1  -- the xp gained (first wildcard)

-- add day entry if first day

xp_gained [day] = xp_gained [day] or { xp = 0}
xp_gained[xp] = xp_gained[xp] + %1

#2
I resolved the addition of the xp with the following code.

xp_gained = xp_gained or {}  -- make xp_gained table
day = os.date ("%A, %m %B %Y") -- Get todays date.
xp = %1  -- the xp gained (first wildcard)

-- add day entry if unique day.

xp_gained [day] = xp_gained [day] or { xp = 0 }
xp_gained [day].xp = xp_gained [day].xp + xp


Unfortunatly, I now have another issue.

/tprint (xp_gained)

gives me

Quote:


"Saturday, 08 August 2008":
"xp"=315
"Tuesday, 08 August 2008":
"xp"=0
"Friday, 08 August 2008":
"xp"=210
"Wednesday, 08 August 2008":
"xp"=0



For some reason when os.date time is called, %m never changes, is this an issue with lua, os.date time, windows 98 or mushclient? Any help would be greatly appreciated!
#3
I resolved all the above issues with this


day = os.date ("%d")
year = os.date("%Y")
month = os.date("%m")
xp_gained = xp_gained or {}  -- make xp_gained table
xp_gained[year] = xp_gained[year] or {};
xp_gained[year][month] = xp_gained[year][month] or {};
xp_gained[year][month][day] = xp_gained[year][month][day] or {};

xp = %1  -- the xp gained (first wildcard)

-- add day entry if unique day.
xp_gained [year][month][day].xp = xp_gained [year][month][day].xp or 0
xp_gained [year][month][day].xp = xp_gained [year][month][day].xp + xp



Unfortunatly, my experince with tables is lacking and I've no idea how to display this data in a usefull manner.

I'd like to be able to display the last 30 days results in

day/month/year - 1000XP Earned.

Format.

/tprint (xp_gained)

gives

Quote:

"2008":
"08":
"05":
"xp"=2205


links to helpfull resources, psuedo code or anything would help greatly!

Australia Forum Administrator #4
Quote:

For some reason when os.date time is called, %m never changes, is this an issue with lua, os.date time, windows 98 or mushclient?


%m is the month, so it never changes because it is still August.

Quote:

day = os.date ("%d")
year = os.date("%Y")
month = os.date("%m")
xp_gained = xp_gained or {} -- make xp_gained table
xp_gained[year] = xp_gained[year] or {};
xp_gained[year][month] = xp_gained[year][month] or {};
xp_gained[year][month][day] = xp_gained[year][month][day] or {};


Isn't that too complicated? You have lots of subtables here.

How about:


date = os.date ("%d-%m-%Y")  -- eg. 06-08-2008

xp_gained [date] = (xp_gained [date] or 0) + xp


Now to print them:



for k, v in pairs (xp_gained) do
  print (k, v)   --> date, xp
end -- for



#5
I think I'm trying to run before I walk.

The logic behind the rather complex table, within a table, within a table. Was for easy indexing, unfortunatly, I had no clue how to re-aquire the data in a resnoable manner.

Your method works great Nick, Thanks!

I'll now just have to see about, how I can aqquire date-ranges etc, from alias input.