Bugs in vector arithmetic
Skript/Server Version
[23:20:39 Server thread/INFO] [Skript] Server Version: git-Paper-783 (MC: 1.16.5)
[23:20:39 Server thread/INFO] [Skript] Skript Version: 2.5.3
[23:20:39 Server thread/INFO] [Skript] Installed Skript Addons:
[23:20:39 Server thread/INFO] [Skript] - skript-placeholders v1.5.1 (https://github.com/APickledWalrus/skript-placeholders)
[23:20:39 Server thread/INFO] [Skript] - Skellett v1.9.11 (https://forums.skunity.com/resources/skellett.24/)
[23:20:39 Server thread/INFO] [Skript] - skript-yaml v1.3.2
[23:20:39 Server thread/INFO] [Skript] - skDragon v0.17
[23:20:39 Server thread/INFO] [Skript] - SkQuery v4.1.4
[23:20:39 Server thread/INFO] [Skript] - SkBee v1.10.2 (https://github.com/ShaneBeee/SkBee)
[23:20:39 Server thread/INFO] [Skript] - FunkySk v1.0.2
Bug Description
I tried to get the opposite vector two ways.
1. Vector arithmetic
As the documentation states, you can do operations like these:
set {_v} to vector 1, 2, 3 // 5
set {_v} to {_v} ++ {_v}
set {_v} to {_v} ++ 5
set {_v} to {_v} -- {_v}
set {_v} to {_v} -- 5
set {_v} to {_v} ** {_v}
set {_v} to {_v} ** 5
set {_v} to {_v} // {_v}
set {_v} to {_v} // 5
So I've tried set {_v} to {_v} ** -1. Result: "can't understand this expression". And it's not even a bug with negative values, you just can't multiply vectors by any scalars. Only this will work: set {_v} to {_v} ** vector(-1,-1,-1) and it will give kinda strange result of x: -0, y: -1, z: -0 when converted to text, but whatever.
2. Changing the length of the vector.
Currently this expression: set vector length of {_v} to -1 will give a vector changed like that:
x: 0, y: 1, z: 0 x: 0, y: 0, z: 0
I expected to get the opposite vector, like this:
x: 0, y: 1, z: 0 x: 0, y: -1, z: 0
At least this works correctly with positive values.
Expected Behavior
Getting the opposite vectors.
Steps to Reproduce
command /test:
trigger:
set {_v} to vector(0,1,0)
message "%{_v}%"
set {_v} to {_v} ** -1
message "%{_v}%"
command /test:
trigger:
set {_v} to vector(0,1,0)
message "%{_v}%"
set vector length of {_v} to -1
message "%{_v}%"
Errors or Screenshots
No response
Other
I think that a separate expression for getting the opposite vectors like the vector opposite to {_v} would be nice.
Agreement
- [x] I have read the guidelines above and confirm I am following them with this report.
Vector arithmetic: The examples on the docs are wrong, the syntax clearly does not allow numbers to be used here, so the examples should be changed.
Changing length of vector: I'm not sure which behaviour should be expected: when you set something to a value, you'd expect it to be set to that value. If you set the vector length of a vector to a negative number, it would be confusing to see that the vector length is not that negative number after the operation, it would instead become the absolute value of that number. The code clearly supports this behaviour, this was intentionally made this way: https://github.com/SkriptLang/Skript/blob/d6dc3db62ecc77af3581cd532eaae3cb7ea44e90/src/main/java/ch/njol/skript/expressions/ExprVectorLength.java#L83-L88
On the other hand, it could logically make sense to set it to the absolute value of the given number, and then possibly multiple all components by -1.
I am going to keep this issue open due to the wrong examples, and unless people think that the paragraph above is the better behaviour, I will close this when the examples are fixed.
The vector arithmetic syntax should be changed to allow for scalar multiplication and division, because until they do, Skript's vectors won't actually form a vector space over the field of real numbers, as vector-scalar multiplication is required (along with vector-vector addition, which is already provided.)
In this strictly mathematical sense, Skript's vectors won't actually be vectors until this operation is supported.
As for the length, I agree with TP that
set vector length of {_v} to {_x}
return vector length of {_v} is {_x}
should hold true for all numeric values of {_x}, and as such the operation of setting the length to a negative value (or, similarly, an undefined variable, NaN, or a non-numeric value) should be undefined.
Numbers used to be able to be converted to vectors, but this caused performance issues, so the converter has since been disabled. This is why the documentation states that it possible.