Everytime i use “or”, that line gets skipped, so that even if the obj == one of those words, it will still return true. But if i just did obj.Name == “Bullet” and skipped the rest, it works.
This is your solution, but I’d say you hear me out:
The impracticality of this long if/then check is obvious. You can easily avoid it by using Tables!
What are tables, you ask? Well one of the best features of LUA. You can store data in any way you like and easily look for it with multiple methods.
That would always return true as there’s no value that equals to "Bullet" and equals to "Bomb".
an and would work
Obj.Name ~= "Bullet" and Obj.Name ~= "Bomb"
To OP: do you understand what does the boolean operator or does? String values are truthy in Lua so it always evaluates to true if you use or with them.
Also adding in, you don’t need the return false at the very end. If nothing is returned, then the function’s output would be nil (which is equal to false)
Since nothing is being returned/outputted, it would be considered be nil. Nil literally means nothing. Nil is nothing. Adding on, I mistyped the part about nil being equal to false. I meant to say that they follow the same principles (in a type of function like the one johnny6288 sent).
For example, take 3 variants of function add():
--1
local function add(n1, n2, n3)
if n1 + n2 == n3 then
return true
end
end
--2
local function add(n1, n2, n3)
if n1 + n2 == n3 then
return true
end
return false
end
--3
local function add(n1, n2, n3)
if n1 + n2 == n3 then
return true
end
return nil
end
If you call the function in this way, it will always have the same output, no matter which variant of the function you use.
if not add(5, 4, 10) then
print("not equal")
end
Again, the way I typed it was wrong (thanks for correcting me), but all I’m trying to say is that he didn’t need a return false at the end of his function.
If I repeat what I’ve said earlier, my point is returning nil when the expected return value is a boolean just isn’t a good practice. So are you implying that he don’t need to explicitally return a value of the expected type and can rely on a implicit boolean coersion instead?
So what if it’ll always have the same result? It doesn’t justify the fact that it’s not a good practice. If I expect a boolean, I explicitally return a boolean.
But why not anyway as the return type is a boolean? Why do you need to rely on an implicit boolean conversion?
No; print takes a variable amount of arguments, if no values are passed it won’t output anything; it’ll print nil if it did return one value of nil.
There’s a difference between return and return nil, implying that it’ll be considered returning one value of nil is wrong.
I was implying that by nothing you mean void am I correct?
This isn’t JavaScript or Python where its nil equivalent are implicitally returned when no return is added. nil/null is a value. Returning no value doesn’t mean it returns a single value nil in Lua.
My point is that:
returning nil isn’t the same as returning no value
relying on implicit boolean conversions when you don’t need to just isn’t a good practice.