The code:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Does not do what you expect. What it does is evaluate `a`, and if it results in a "true" value (anything other than `false` or `nil`), it uses that value. Otherwise, it evaluates `b`, and if it results on a "true" value, it uses that value. Same for `c`.
Since `a` in your case is the string "default:gold_lump", `a` is not "false", so the expression (a or b or c) results in "default:gold_lump". Then Lua compares `wieldname` to the result of the expression. The expression `("default:gold_lump" or ...)` always result in "default:gold_lump".
You have two approaches. You can explicitly test for the strings:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
if wieldname == "foo" or wieldname == "bar" or wieldname == "baz" or ...
Or you can use a table mapping accepted values to `true`:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local valid = {
["default:foo"] = true,
["default:bar"] = true,
-- ...
}
-- Then in your check
if valid[wieldname] then
print("I am doing something.")
end
Which one is better is up to you. I'd use the former if the list of valid options is short, but use the latter if you need lots of items.