These were previously marked as operators, but unfortunately it is not possible for us to always compile the correct comparison.
Given the following example:
export function f(p1: Value, p2: Value) {
if (p1 == p2) {
notify("Equals!");
}
}
It is impossible to know whether the user meant compareItem, compareEntity or checkNumber (with ==).
One approach, which I've seen traces of in the code, might be to add virtual properties on Value that allows the user to indicate whether they want to interpret it as an item, entity or number.
But as a user, I would prefer to be able to simply write
if (compareItem(p1, p2)) {
// ...
}
which matches what I'm used to from the game, and clearly shows my intent.
This also allows me to write:
switch (checkNumber(p1, p2)) {
case ">=":
case "=":
notify("Hello World");
break;
}
While only invoking checkNumber once. It would be nice to be able to write:
These were previously marked as operators, but unfortunately it is not possible for us to always compile the correct comparison.
Given the following example:
It is impossible to know whether the user meant
compareItem
,compareEntity
orcheckNumber
(with==
).One approach, which I've seen traces of in the code, might be to add virtual properties on
Value
that allows the user to indicate whether they want to interpret it as an item, entity or number.But as a user, I would prefer to be able to simply write
which matches what I'm used to from the game, and clearly shows my intent.
This also allows me to write:
While only invoking checkNumber once. It would be nice to be able to write:
But this requires more work with the compiler, and is still ambiguous since the user could have meant:
The implementation of the
==
operator can be kept, and perhaps still improved, but I'd like to also be able to use these instructions as-is.