Skript
Skript copied to clipboard
Integer division/multiplication
Suggestion
Skript should be able to do proper integer division/multiplication as you can in java without having to use round(division/multiplication). A solution could be adding more number converters.
Why?
It's a huge inconvenience and took me quite some time to figure out because I assumed Skript would just do integer division/multiplication and give me an integer.
Other
For example, I have to round this to get it as integer type:
function toCominbed(i1: integer, i2: integer) :: integer:
return round({_i1} * 1000 + {_i2})
I love you TPGames ❤️
Agreement
- [X] I have read the guidelines above and confirm I am following them with this suggestion.
Oh, thanks to this I finally understood why some of my vars have become floats. Because I've used mod(), which I didn't expect to return a float. But I don't see multiplication outputting floats, has something changed?
This:
load yaml "plugins/Skript/scripts/test.yml" as "test"
set yaml value "1" from "test" to 2+2
set yaml value "2" from "test" to 2-2
set yaml value "3" from "test" to 2*2000
set yaml value "4" from "test" to 2/2
set yaml value "5" from "test" to mod(2,2)
save yaml "test"
... gives this yaml:
'1': 4
'2': 0
'3': 4000
'4': 1.0
'5': 0.0
Any arithmetic operation done with variables returns a non-integer type: because the return type of a variable isn't known at parsetime (besides that it has to be a number according to the pattern), and the return type of the arithmetic expression is determined at parsetime, we set the return type to be a non-integer type.
For division and exponentation we always pick a non-integer return type, since even integer division (meaning division with integers, not division resulting in an integer) can returns a non-integer number, e.g. 1/2.
For the mod function, we don't keep into account whether the inputs are integers or not, we just always return a non-integer type.
However, no addon should rely on Skript returning specifically Double or Long (or other numeric types). If there is anything within Skript that only work with integer types, that's a problem, but most of these problems should be fixed by adding more number converters as said above (e.g. Number -> Long).