I for one, really really really like lua as opposed to the euox scripting language.
I hate to do this and wonder if I'm breaking a taboo, you should also check out easyUO's openEUO forum. A few guys over there like Snicker7 and ximan are excellent lua coders, from what I can tell.
In terms of good coding axioms, I try to practice lua script writing as if I were writing in C++. I like writing modular functions so I can copy/paste them into new scripts as needed and know that those functions are going to work as intended. One axiom I code with is avoiding upvalues in functions. If you're not entirely sure what an upvalue is in lua, you can check out the lua page http://www.lua.org/pil/6.1.html
in short, I avoid this at all cost
[code]
--some code
local resourcebagID = UO.LtargetID
--blah more code
function GetRegs()
--blah, ScanItems/GetItems or some appropriate call to a FindItem sub.
if FountItemContID == resourcebagID then
--blah
end
return
end
In that example, resourcebagID is known as an upvalue. It was defined in a local scope that the function was defined in. In lua, if you do not define a variable it will look in the parent scope for a definition. I prefer to send all variables in as arguments and define all function constants within the function itself.
Something else I do, is create a function for each simple task I want to do. Then create functions for each Macro task I wish to do, and then use a main driving loop that is nothing but function calls. Keeps your thoughts organized and much easier to track down bugs in the script. For example:
function MoveItem(id,dropbag,stack)
UO.Drag(id,(stack or 1))
UO.DropC(dropbag or UO.BackpackID)
wait(1000)
return
end
function MoveAllOfType(Type,Col,contID)
--Appropriate finditem call for Type/Col
for k,v in pairs(AllItems) do
MoveItem(v['ID'],contID)
end
return
end
Now I can use those subs when ever I want in any script. A bod sorting script, Looting script, etc and if they fail to move something, then I know it's a consequence of something else, not those functions.
I am also a comment happy fella. It makes it easier to understand your own work later, as well as for others to learn from you.
[/code]