
Error With Parsing as a Integer
Closed this issue · 6 comments
Skript/Server Version
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0mSkript's aliases can be found here: �[36mhttps://github.com/SkriptLang/skript-aliases�[0m
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0mSkript's documentation can be found here: �[36mhttps://docs.skriptlang.org/�[0m
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0mSkript's tutorials can be found here: �[36mhttps://docs.skriptlang.org/tutorials�[0m
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0mServer Version: �[36m1.21.4-15-bb76819 (MC: 1.21.4)�[0m
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0mSkript Version: �[36m2.11.1 (skriptlang-github)�[0m
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0mInstalled Skript Addons: �[36m�[0m
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0m - SkriptJSON v1.0.0
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0m - SkBee v3.11.2 (https://github.com/ShaneBeee/SkBee)
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0m - SkUniversal v2.13
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0m - skUtilities v0.9.2 (https://tim740.github.io/)
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0m - SkQuery v4.3.2
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0m - skript-db v0.5
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0mInstalled dependencies: �[36m�[0m
[13:53:22 INFO]: �[37m[�[33mSkript�[37m] �[0m - Vault v2.10.0
Bug Description
Here's My Code:
set {_i} to getFriendsValue(player's uuid,"Coins") while {_i} starts with " ": set {_i} to "%subtext of {_i} from characters 2 to the length of {_i}%" while {_i} ends with " ": set {_i} to "%subtext of {_i} from characters 1 to (the length of {_i} - 1)%" set {_i} to "%{_i}%" parsed as an integer send "%{_i}%" to player add 0.1 to {_i} setFriendsValue(player's uuid,"Coins","%{_i}%")
So Basically the First function returns a Text like " 0.1" but after parsing as an integer it is prints out if i comment out the parsing line it prints out "0.1" can you help me
Code with the functions if that Helps event thoug i am using both of them in other skripts that work completely fine:
`function setFriendsValue(uuid: text, key: text, val: text):
set {_file} to "plugins/FriendsSystem/data/%{_uuid}%.yml"
if file {_file} doesn't exist:
create file {_file}
set {_lines::*} to file contents of {_file}
set {_found} to false
loop {_lines::*}:
set {_l} to loop-value
set {_spaces} to ""
while {_l} starts with " ":
set {_l} to subtext of {_l} from character 2 to (the length of {_l})
set {_spaces} to " %{_spaces}%"
if {_l} starts with "%{_key}%:":
set {_index} to loop-index
set {_lines::%{_index}%} to "%{_spaces}%%{_key}%: %{_val}%"
set {_found} to true
stop loop
if {_found} is false:
add "%{_key}%: %{_val}%" to {_lines::*}
set file contents of {_file} to {_lines::*}
function getFriendsValue(uuid: text, key: text) :: text:
set {_file} to "plugins/FriendsSystem/data/%{_uuid}%.yml"
if file {_file} doesn't exist:
return ""
set {_lines::*} to file contents of {_file}
loop {_lines::*}:
set {_l} to loop-value
while {_l} starts with " ":
set {_l} to subtext of {_l} from character 2 to (the length of {_l})
if {_l} starts with "%{_key}%:":
set {_value} to substring of {_l} from (length of "%{_key}%: ") to (length of {_l})
set {friendssystem::%{_uuid}%::%{_key}%} to {_value}
return {_value}
return ""`
Expected Behavior
It should parse the integer correct
Steps to Reproduce
I ran the Code
Errors or Screenshots
No response
Other
No response
Agreement
- I have read the guidelines above and affirm I am following them with this report.
Found a Workaround Bug is the dot.
set {_i} to getFriendsValue(player's uuid,"Coins") while {_i} starts with " ": set {_i} to "%subtext of {_i} from characters 2 to the length of {_i}%" while {_i} ends with " ": set {_i} to "%subtext of {_i} from characters 1 to (the length of {_i} - 1)%" replace all "." in {_i} with "" set {_i} to "%{_i}%" parsed as an integer send "%{_i}%" to player set {_i} to {_i} / 10 add 0.1 to {_i} setFriendsValue(player's uuid,"Coins","%{_i}%") send "&3Du kriegst +0.1 Coins" to player
Numbers with decimal places are known in Skript as number
, attempting to parse them as an integer will return none, try parsing as a number instead.
Tried switching to it now, because some players had Issues with the old code not working but somehow this does not work with integer or number:
send "%getFriendsValue(player's uuid,"Coins")%" to player
set {_i} to "%getFriendsValue(player's uuid,"Coins")%" parsed as number
send "%{_i}%" to player
add 1 to {_i}
setFriendsValue(player's uuid,"Coins","%{_i}%")
this first sends 1 and then
sorry I'm a bit confused, and would love to help you in a proper help channel such as on SkUnity, but why are you converting it to a string and then parsing? does it not already return a number?
I am not Converting it to String that text conversion is useless the function returns a string here's the full relevant code:
send "%getFriendsValue(player's uuid,"Coins")%" to player set {_i} to getFriendsValue(player's uuid,"Coins") parsed as number send "%{_i}%" to player add 1 to {_i} setFriendsValue(player's uuid,"Coins","%{_i}%")
this first sends 1 and then none