I'm fiddling with some code I found on some forums, but I've only ever learned Java, so I'm a little out of my element. Here's the snippet I'm playing with:
/run
function FnH()
for i=0,4 do
for j=1,GetContainerNumSlots(i) do
local t={GetItemInfo(GetContainerItemLink(i,j) or 0)}
if t[7]=="Herb" and select(2,GetContainerItemInfo(i,j))>=5 then
return i.." "..j, t[1]
end
end
end
end
This is using WoW's addon API. With what little I know, this is a search and make a list function that lists items that let t[7]=Herb while also having more than 5 of them. If Lua does arrays similarly, t[0] should be Item Name. I want to exclude an item with the name "blahblah", but I don't understand Lua's boolean operands.
In Java, it would be something along the lines of
if(itemX.getItemType()=="Herb" && itemX.getAmount()>5 && itemX.getName()!="blahblah")
do stuff
else skip to next item
I see with Lua that they use "and" and "or", but how do I say "and not this"?
Note that Lua indexes tables starting from index 1, not 0 like some other languages, so if you have table
local t = {"John", "Laura", "Herb"}, thent[1] == "John"andt[3] == "Herb".As others have said, the equivalent Lua operations are
and,or, andnot, with inequality written as~=, so the code you have can be written as:You can also change the last condition to
and not (itemX.getName()=="blahblah")as these are equivalent.Also, I'm not sure about WoW API, but those
itemXcalls should probably beitemX:getItemType(),itemX:getAmount()and so on (note using:notation instead of.notation); see OO-programming section in Programming in Lua.