Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ XP Per Day Script.
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Shigs
(27 posts) Bio
|
Date
| Tue 05 Aug 2008 03:59 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Shigs
(27 posts) Bio
|
Date
| Reply #1 on Tue 05 Aug 2008 04:16 PM (UTC) |
Message
| 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
| Top |
|
Posted by
| Shigs
(27 posts) Bio
|
Date
| Reply #2 on Tue 05 Aug 2008 07:30 PM (UTC) |
Message
| 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! | Top |
|
Posted by
| Shigs
(27 posts) Bio
|
Date
| Reply #3 on Tue 05 Aug 2008 10:18 PM (UTC) |
Message
| 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!
| Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #4 on Tue 05 Aug 2008 10:40 PM (UTC) |
Message
|
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
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shigs
(27 posts) Bio
|
Date
| Reply #5 on Tue 05 Aug 2008 11:30 PM (UTC) |
Message
| 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. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
15,875 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top