If I wanted to check that this variable is null, I would do: if (Counter = false)
So logically, if I wanted to check that this variable isn’t null, I should be able to do: if (Counter = true)
However, it does not seem to work. It always returns false.
Is it intended behavior? Or am I missing something?
Please select what you are reporting on:
Verse
What Type of Bug are you experiencing?
Verse
Steps to Reproduce
Have a nullable (option) variable, like such: ?type,
Compare it with true in an if statement.
Expected Result
If the variable has a value, it should return true.
Observed Result
Even when the variable has a value, it returns false.
Platform(s)
Desktop (I expect all platforms to behave the same).
I guess a way to think about it is that false is essentially a value in a way?
eg a float can be any number and a ?float can be any number + false. but yea to be fair it also took me quite a while to understand the logic behind that but it’s something Im used to now.
I prefer to think of ?int more as being like C++'s int*, and false as the equivalent to nullptr.
So if (Counter = false) would be the same as if (Counter == nullptr),
and if (Counter = true) the same as if (Counter != nullptr).
This is for you to print the value so you can see it’s type is ?int (not boolean). Because this type can hold an optional integer you almost always want to store something you may need to use later. If you do not need to know specific integer, simply use the logic type instead (boolean).
It still doesn’t explain why if (Counter = true) shouldn’t work.
vBool : ?logic = false
if (vBool = false): # Returns true if there is no value.
Print("Boolean has no value.")
# ----------------------------------------------
vBool : ?logic = option{false}
if (vBool? = false): # Retrieves value (if there is one) then compares.
Print("Boolean has a value and is false.")
# ----------------------------------------------
vBool : ?logic = option{false} # OR option{true}.
if (vBool = true): # Doesn't work. Should return true if there is a value.
Print("Boolean has a value.")
# ----------------------------------------------
vBool : ?logic = option{true}
if (vBool? = true): # Retrieves value (if there is one) then compares.
Print("Boolean has a value and is true.")
Above is what should logically work, but like I said, = true to check that there is a value does not work.
Yes, it is clearly a bug or an oversight.
It never being true is clearly not something that should be happening when there the variable has an optionable value.
On top of that, there is no ambiguity when comparing an optionable variable to true like such since you aren’t fetching its value. It’s not like true could be confused for option{true}.
Let’s hope a dev will show up here. I’ve come across a fair amount of inconsistent things while using Verse and fixing issues such as this one would be a first step to making writing code in Verse a much more enjoyable experience for me (and others) who are used to some things that don’t work in Verse working in other more popular languages.