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
➜ Plugins
➜ Aardwolf Equipment CSV File Exporter
Aardwolf Equipment CSV File Exporter
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Mendaloth
(14 posts) Bio
|
Date
| Sat 30 Oct 2010 10:24 PM (UTC) |
Message
| I'm currently working on a plugin that will automatically wear my equipment as I level. My first step was figuring out what equipment I want to wear, so I made this plugin that will take all the equipment in a bag and export the stats of those items to a CSV file. I'm sure there are bugs that I have missed, and I welcome any feedback. I've only tested it with Mush 4.61, but based on the Release notes I believe it'll work back to 3.74.
http://mushclient.pastebin.com/VGgj2VFx | Top |
|
Posted by
| Mendaloth
(14 posts) Bio
|
Date
| Reply #1 on Sun 31 Oct 2010 02:30 AM (UTC) |
Message
| Never can leave these things once I've finished them.
I added the ability to export more than one bag, worn equipment, and equipment just in your inventory.
http://mushclient.pastebin.com/NXrLEdvW | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sun 31 Oct 2010 06:16 AM (UTC) |
Message
| Just as a suggestion, instead of a lot of concatenation, you can do this:
t = {}
table.insert (t, "foo")
table.insert (t, "bar")
table.insert (t, "x")
table.insert (t, "22")
print (table.concat (t, ","))
Output is:
And to remove a bit of wordiness:
t = {}
function item (x)
table.insert (t, x)
end -- function
item ("foo")
item ("bar")
item ("x")
item (22)
print (table.concat (t, ","))
Gives the same results. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 31 Oct 2010 06:21 AM (UTC) |
Message
| And that lets you expand it to handle things with commas in them:
t = {}
function item (x)
if string.match (x, ",") then
x = '"' .. x .. '"'
end -- if
table.insert (t, x)
end -- function
item ("foo")
item ("bar")
item ("x")
item ("food, water")
item (22)
print (table.concat (t, ","))
Results:
foo,bar,x,"food, water",22
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #4 on Sun 31 Oct 2010 06:34 AM (UTC) |
Message
| To clarify what Nick said about concatenation, a line like this is fine:
Lua pushes each value onto its stack and executes a single concatenation opcode. However, the code you have in Get_Equipment_Line executes a whole bunch of concatenation opcodes, because you're stopping between each one and storing it in a temporary variable. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Mendaloth
(14 posts) Bio
|
Date
| Reply #5 on Mon 01 Nov 2010 10:10 PM (UTC) |
Message
| Thanks I appreciate the feedback.
I made the change and posted it on pastebin. Definitely makes it look cleaner!
http://mushclient.pastebin.com/hx7CDKCW | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #6 on Mon 01 Nov 2010 10:58 PM (UTC) Amended on Mon 01 Nov 2010 10:59 PM (UTC) by Twisol
|
Message
|
Mendaloth said: http://mushclient.pastebin.com/hx7CDKCW
Your explode() function actually already exists as Nick's utils.split function. Example:
utils.split("foo bar baz", " ")
-- {"foo", "bar", "baz"}
You should look into using 'local' a lot more, too (and I mean, always use 'local' unless you're sure you don't want that). You have lots of variables in your functions that are defined as globals, rather than local to that function. One wrong move and you might accidentally have one function affect another function's data, and you'll have a hard-to-find bug on your hands.
Also, don't be afraid to use intermediate local variables. In some functions (like Get_Next_Equipment_Item_Data()), you're using equipment[current_equipment_objectid] over and over and over and over. Every time you write that, Lua has to access the table yet again to retrieve the same value (because as far as I can tell, each access is definitely getting the same value each time). Store it in a temporary local (i.e. "local o") and not only will you save on extra lookups, but the code will also be cleaner.
Another quick tip: In cases like the one below, consider using string.format(). It can make it clearer what the string really looks like:
SendNoEcho("get " .. o.objectid .. " " .. o.container_id)
-- instead, try
SendNoEcho(("get %s %s"):format(o.objectid, o.container_id))
One odd thing I noticed...
for key, value in pairs(equipment) do
if not equipment[key].details_captured then
return equipment[key].objectid -- index will be nil, the beginning
end
end
You're using equipment[key] there. But, pairs() returns a key,value pair, such that equipment[key] == value. You could use 'value' instead and save the extra table lookups. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #7 on Tue 02 Nov 2010 08:35 AM (UTC) |
Message
| I was bored, so I decided to tinker with the exporter plugin and clean it up a little bit. Here's what I ended up with:
http://mushclient.pastebin.com/hVqWmqHb
I logged in to Aardwolf to test it, and it seems to work fine. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Mendaloth
(14 posts) Bio
|
Date
| Reply #8 on Sat 06 Nov 2010 (UTC) |
Message
| Thanks so much for the feedback and help rewriting! I was having computer issues or I would have responded sooner.
I added one feature which other users had requested (the ability to reset your imported equipment, without restarting Mushclient) and removed the debug note line so that you won't see the messy lines from the Mud.
I think with all of your help, it is pretty much done!
http://mushclient.pastebin.com/Kf21TLTZ
Also I noticed you call the local variables 0. Is that a LUA thing, programming concept, or just a personal thing you do? If there is a MUSHClient or LUA style I'd love to know, since my code tends to be all over the place with naming conventions. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #9 on Sat 06 Nov 2010 12:16 AM (UTC) |
Message
| He actually called them "o" (the lower-case letter "O" as in Oscar, not zero).
Personally I think that there is a potential for confusion there (you obviously thought it was a zero).
My guess it is short for "object" and he used that to save space.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #10 on Sat 06 Nov 2010 01:04 AM (UTC) |
Message
| Potential for confusion? Kind of.
Most people who script/program find that having a good (monospace) font for programming is pretty important. A good font has things like an easy recognizable difference between o, O and 0. Or i, 1 and l.
(Of course Nick already knows this, advocating the use of Dina left and right, but I figured I'd reply never the less.) | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #11 on Sat 06 Nov 2010 05:32 AM (UTC) |
Message
| Nick's correct, I used 'o' for 'object'. Since it's used so frequently, it's easier and clearer to give it a very short name.
As for naming conventions, I usually name variables (including functions) in all lowercase, separating words with underscores. For library tables (i.e. tables returned from libraries I've written, such as PPI) I usually use CamelCase. I also use CamelCase for methods on tables, like mywindow:DrawLine(). Of course, this is my personal method; others may use a different one, and I myself probably deviate from time to time. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #12 on Sat 06 Nov 2010 10:50 AM (UTC) |
Message
| Although some things are a matter of taste, I prefer to have an object be shortened to obj. The two letters don't make a difference, but it reduces confusion, and unlike the standard variable 'i' people tend to use for integers in loops, there's no real 'object' type in Lua. You have tables, but a 't' would be more suitable, although if one is familiar with other language, one might think that would refer to type.
Besides, in the same line of reasoning, 'object' might refer to a baseclass called 'object', not a variable of some sort of object. (Yeah, those aren't Lua, but I can't help but think that way where this subject comes up.) | 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.
35,098 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top