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