Rounding just fails.

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Jacob105

Member
Aug 7, 2020
48
1
8
24
Code:
            if {_combatElapsed} <= 20 seconds:
                set {_combat} to rounded up {_combat}
                set score "&r&7&m---------------------------" in sidebar of loop-player to 14
                set score "&b&lCooldowns" in sidebar of loop-player to 13
                set score " &3* &bCombat: &f%{_combat}%" in sidebar of loop-player to 12
(Combat and combat elapsed are supposed to be separate)
Returns as <none>
Any ideas on how to fix it?
unknown.png
 
First off, check if these variables are actually set. If it returns none then it's because the variable probably doesn't have any value (= it isn't set)
You can't use local variables, if you haven't set it yet. Local variables are only variables that exist and must be set during one instance (=event or whatever it is). Outside of that instance the variable doesn't exist, hence why it's local. You often use local variables to save and use information during one specific event, but don't want it to be used across the rest of the server. That variable with it's set value only exists within that event.

Btw is the {_combat} supposed to be a PvPTimer or how many kills a player has? You haven't specified what those variables actually are and how you saved them, so it's hard to confirm that the rounding is the problem. I'd would've expected Skript to just round the number to 0 and not display '<none>'.

Here is my spaghetti code for Number Accuracy if that is an issue though, the first number is your variable, the second number is how many decimals you want to see. Else you're going to have to change the number accuracy in the skript options file, but this will change the number accuracy across the rest of skript too, so I prefer to just create a function. So here's how I do it, although probably not the cleanest way:

Code:
function NumberAccuracy(n: number, a: number) :: text:
    set {_amount} to rounded ({_n}*10^{_a})
    if length of "%{_amount}%" is greater than {_a}:
        set {_firstpart} to subtext of "%{_amount}%" from characters 1 to length of "%{_amount}%"-{_a}
        set {_secondpart} to subtext of "%{_amount}%" from characters "%{_amount}%"'s length-{_a}+1 to length of "%{_amount}%"
    else:
        set {_firstpart} to 0       
        set {_secondpart} to {_amount}
    set {_n} to {_a}
    remove length of "%{_secondpart}%" from {_n}
    loop {_n} times:
        set {_secondpart} to "0%{_secondpart}%"
    loop {_a} times:
        if last character of "%{_secondpart}%" is "0":
            set {_secondpart} to subtext of "%{_secondpart}%" from characters 1 to length of "%{_secondpart}%"-1
    if {_secondpart} is not set:
        set {_return} to "%{_firstpart}%"
    else:   
        set {_return} to "%{_firstpart}%.%{_secondpart}%"
    return "%{_return}%"
 
First off, check if these variables are actually set. If it returns none then it's because the variable probably doesn't have any value (= it isn't set)
You can't use local variables, if you haven't set it yet. Local variables are only variables that exist and must be set during one instance (=event or whatever it is). Outside of that instance the variable doesn't exist, hence why it's local. You often use local variables to save and use information during one specific event, but don't want it to be used across the rest of the server. That variable with it's set value only exists within that event.

Btw is the {_combat} supposed to be a PvPTimer or how many kills a player has? You haven't specified what those variables actually are and how you saved them, so it's hard to confirm that the rounding is the problem. I'd would've expected Skript to just round the number to 0 and not display '<none>'.

Here is my spaghetti code for Number Accuracy if that is an issue though, the first number is your variable, the second number is how many decimals you want to see. Else you're going to have to change the number accuracy in the skript options file, but this will change the number accuracy across the rest of skript too, so I prefer to just create a function. So here's how I do it, although probably not the cleanest way:

Code:
function NumberAccuracy(n: number, a: number) :: text:
    set {_amount} to rounded ({_n}*10^{_a})
    if length of "%{_amount}%" is greater than {_a}:
        set {_firstpart} to subtext of "%{_amount}%" from characters 1 to length of "%{_amount}%"-{_a}
        set {_secondpart} to subtext of "%{_amount}%" from characters "%{_amount}%"'s length-{_a}+1 to length of "%{_amount}%"
    else:
        set {_firstpart} to 0      
        set {_secondpart} to {_amount}
    set {_n} to {_a}
    remove length of "%{_secondpart}%" from {_n}
    loop {_n} times:
        set {_secondpart} to "0%{_secondpart}%"
    loop {_a} times:
        if last character of "%{_secondpart}%" is "0":
            set {_secondpart} to subtext of "%{_secondpart}%" from characters 1 to length of "%{_secondpart}%"-1
    if {_secondpart} is not set:
        set {_return} to "%{_firstpart}%"
    else:  
        set {_return} to "%{_firstpart}%.%{_secondpart}%"
    return "%{_return}%"
Hey, thanks for your answer, it's a combat log timer, also it IS set.
FULL CODE
Code:
every tick:
    loop all players:
        wipe loop-player's sidebar
        set name of sidebar of loop-player to "&b&lNitro&7 ┃ &3KitPVP &7(Alpha)"
        set {_combatElapsed} to difference between now and {combatlog::%loop-player%::time}
        set {_combat} to difference between 20 seconds and {_combatElapsed}
        if {event} is "Combo":
            if {_combatElapsed} <= 20 seconds:               
                set score "&r&7&m---------------------------" in sidebar of loop-player to 16
                set {_timeElapsed} to difference between {comboevent::timer} and now
                set score "&b&lEvents & Cooldowns" in sidebar of loop-player to 15
                set score " &3* &bEvent: &f%{event}%" in sidebar of loop-player to 14
                set score " &3* &bTime: &f%{_timeElapsed}%" in sidebar of loop-player to 13
                set score " &3* &bCombat: &f%{_combat}%" in sidebar of loop-player to 12
                set score " " in sidebar of loop-player to 11
                set score "&b&lYou" in sidebar of loop-player to 10
                if {levelcolored::%loop-player%} is not set:
                    set {levelcolored::%loop-player%} to "&70"
                if {level::%loop-player%} is not set:
                    set {level::%loop-player%} to 0
                if {XP::%loop-player%} is not set:
                    set {XP::%loop-player%} to 0
                if {XPNeeded::%loop-player%} is not set:
                    set {XPNeeded::%loop-player%} to 10
                set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
                if {kills::%loop-player%} is not set:
                    set {kills::%loop-player%} to 0
                set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
                if {deaths::%loop-player%} is not set:
                    set {deaths::%loop-player%} to 0
                set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
                if {killstreak::%loop-player%} is not set:
                    set {killstreak::%loop-player%} to 0
                if {bestkillstreak::%loop-player%} is not set:
                    set {bestkillstreak::%loop-player%} to 0
                set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
                if {KDR::%loop-player%} is not set:
                    set {KDR::%loop-player%} to 0
                set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
                if {beloved::%loop-player%} is not set:
                    set {beloved::%loop-player%} to 0
                set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
                if {balance::%loop-player%} is not set:
                    set {balance::%loop-player%} to "0.00"
                set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
                set score "&7&m---------------------------&r" in sidebar of loop-player to 1
            else:
                set score "&r&7&m---------------------------" in sidebar of loop-player to 15
                set {_timeElapsed} to difference between {comboevent::timer} and now
                set score "&b&lEvents" in sidebar of loop-player to 14
                set score " &3* &bEvent: &f%{event}%" in sidebar of loop-player to 13
                set score " &3* &bTime: &f%{_timeElapsed}%" in sidebar of loop-player to 12
                set score " " in sidebar of loop-player to 11
                set score "&b&lYou" in sidebar of loop-player to 10
                if {levelcolored::%loop-player%} is not set:
                    set {levelcolored::%loop-player%} to "&70"
                if {level::%loop-player%} is not set:
                    set {level::%loop-player%} to 0
                if {XP::%loop-player%} is not set:
                    set {XP::%loop-player%} to 0
                if {XPNeeded::%loop-player%} is not set:
                    set {XPNeeded::%loop-player%} to 10
                set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
                if {kills::%loop-player%} is not set:
                    set {kills::%loop-player%} to 0
                set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
                if {deaths::%loop-player%} is not set:
                    set {deaths::%loop-player%} to 0
                set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
                if {killstreak::%loop-player%} is not set:
                    set {killstreak::%loop-player%} to 0
                if {bestkillstreak::%loop-player%} is not set:
                    set {bestkillstreak::%loop-player%} to 0
                set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
                if {KDR::%loop-player%} is not set:
                    set {KDR::%loop-player%} to 0
                set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
                if {beloved::%loop-player%} is not set:
                    set {beloved::%loop-player%} to 0
                set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
                if {balance::%loop-player%} is not set:
                    set {balance::%loop-player%} to "0.00"
                set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
                set score "&7&m---------------------------&r" in sidebar of loop-player to 1
        else if {event} is "Target":
            if {_combatElapsed} <= 20 seconds:               
                set score "&r&7&m---------------------------" in sidebar of loop-player to 17
                set {_timeElapsed} to difference between {targetevent::timer} and now
                set score "&b&lEvents & Cooldowns" in sidebar of loop-player to 16
                set score " &3* &bEvent: &f%{event}%" in sidebar of loop-player to 15
                set score " &3* &bTarget: &f%{thetarget}%" in sidebar of loop-player to 14
                set score " &3* &bTime: &f%{_timeElapsed}%" in sidebar of loop-player to 13
                set score " &3* &bCombat: &f%{_combat}%" in sidebar of loop-player to 12
                set score " " in sidebar of loop-player to 11
                set score "&b&lYou" in sidebar of loop-player to 10
                if {levelcolored::%loop-player%} is not set:
                    set {levelcolored::%loop-player%} to "&70"
                if {level::%loop-player%} is not set:
                    set {level::%loop-player%} to 0
                if {XP::%loop-player%} is not set:
                    set {XP::%loop-player%} to 0
                if {XPNeeded::%loop-player%} is not set:
                    set {XPNeeded::%loop-player%} to 10
                set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
                if {kills::%loop-player%} is not set:
                    set {kills::%loop-player%} to 0
                set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
                if {deaths::%loop-player%} is not set:
                    set {deaths::%loop-player%} to 0
                set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
                if {killstreak::%loop-player%} is not set:
                    set {killstreak::%loop-player%} to 0
                if {bestkillstreak::%loop-player%} is not set:
                    set {bestkillstreak::%loop-player%} to 0
                set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
                if {KDR::%loop-player%} is not set:
                    set {KDR::%loop-player%} to 0
                set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
                if {beloved::%loop-player%} is not set:
                    set {beloved::%loop-player%} to 0
                set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
                if {balance::%loop-player%} is not set:
                    set {balance::%loop-player%} to "0.00"
                set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
                set score "&7&m---------------------------&r" in sidebar of loop-player to 1
            else:
                set {_timeElapsed} to difference between {targetevent::timer} and now
                set score "&r&7&m---------------------------" in sidebar of loop-player to 16
                set score "&b&lEvents" in sidebar of loop-player to 15
                set score " &3* &bEvent: &f%{event}%" in sidebar of loop-player to 14
                set score " &3* &bTarget: &f%{thetarget}%" in sidebar of loop-player to 13
                set score " &3* &bTime: &f%{_timeElapsed}%" in sidebar of loop-player to 12
                set score " " in sidebar of loop-player to 11
                set score "&b&lYou" in sidebar of loop-player to 10
                if {level::%loop-player%} is not set:
                    set {level::%loop-player%} to 0
                if {levelcolored::%loop-player%} is not set:
                    set {levelcolored::%loop-player%} to "&70"
                if {XP::%loop-player%} is not set:
                    set {XP::%loop-player%} to 0
                if {XPNeeded::%loop-player%} is not set:
                    set {XPNeeded::%loop-player%} to 10
                set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
                if {kills::%loop-player%} is not set:
                    set {kills::%loop-player%} to 0
                set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
                if {deaths::%loop-player%} is not set:
                    set {deaths::%loop-player%} to 0
                set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
                if {killstreak::%loop-player%} is not set:
                    set {killstreak::%loop-player%} to 0
                if {bestkillstreak::%loop-player%} is not set:
                    set {bestkillstreak::%loop-player%} to 0
                set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
                if {KDR::%loop-player%} is not set:
                    set {KDR::%loop-player%} to 0
                set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
                if {beloved::%loop-player%} is not set:
                    set {beloved::%loop-player%} to 0
                set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
                if {balance::%loop-player%} is not set:
                    set {balance::%loop-player%} to "0.00"
                set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
                set score "&7&m---------------------------&r" in sidebar of loop-player to 1
        else:
            if {_combatElapsed} <= 20 seconds:               
                set score "&r&7&m---------------------------" in sidebar of loop-player to 14
                set score "&b&lCooldowns" in sidebar of loop-player to 13
                set score " &3* &bCombat: &f%{_combat}%" in sidebar of loop-player to 12
                set score " " in sidebar of loop-player to 11
            else:
                set score "&r&7&m---------------------------" in sidebar of loop-player to 11
            set score "&b&lYou" in sidebar of loop-player to 10
            if {level::%loop-player%} is not set:
                set {level::%loop-player%} to 0
            if {levelcolored::%loop-player%} is not set:
                set {levelcolored::%loop-player%} to "&70"
            if {XP::%loop-player%} is not set:
                set {XP::%loop-player%} to 0
            if {XPNeeded::%loop-player%} is not set:
                set {XPNeeded::%loop-player%} to 10
            set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
            if {kills::%loop-player%} is not set:
                set {kills::%loop-player%} to 0
            set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
            if {deaths::%loop-player%} is not set:
                set {deaths::%loop-player%} to 0
            set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
            if {killstreak::%loop-player%} is not set:
                set {killstreak::%loop-player%} to 0
            if {bestkillstreak::%loop-player%} is not set:
                set {bestkillstreak::%loop-player%} to 0
            set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
            if {KDR::%loop-player%} is not set:
                set {KDR::%loop-player%} to 0
            set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
            if {beloved::%loop-player%} is not set:
                set {beloved::%loop-player%} to 0
            set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
            if {balance::%loop-player%} is not set:
                set {balance::%loop-player%} to "0.00"
            set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
            set score "&7&m---------------------------&r" in sidebar of loop-player to 1
 
Thanks for sending the full code, buddy. I've taken a look at it and tested it out myself. And saw that the problem likely lies here.
  • set {_combatElapsed} to difference between now and {combatlog::%loop-player%::time}
  • set {_combat} to difference between 20 seconds and {_combatElapsed}

So these are the 2 problems that are likely to be present here.
  1. You can compare 2 objects but only under the condition that the values you compare are both the same type. Such as 2 dates or 2 timespans, but not a date and a timespan. Either in the first line or the second line I'm pretty sure that you could've tried to compare a timespan and a date, and that will return 'none', if it's an invalid comparison (=both objects are not the same type)
  2. The other problem you could possible have. In the first snippet of code that you sent, is that you tried to round the difference between 2 (probably) dates or timespans. Now, you can round the difference between 2 numbers, but not between 2 dates or timespan. Nor can you round an amount of time or date in general.
I'm suspecting problem 1 to likely be the problem here. because the way you saved {combatlog::%loop-player%::time} indicated at the end of the variable name, that it's a probably a time(span) and not a date. Btw the expression 'now' is a date and not an amount of time. '20 seconds' is an amount of time and not a date. What would be a date would be '20 seconds later', instead of just '20 seconds'

Another thing I wanted to mention is that I've never seen the expression 'rounded up' be used in skript. Is it a valid expression? I'm pretty sure, Skript has the built in function ceil() that would give the result that you wanted in that piece of code. and Skript also has the expression 'rounded', but after testing, I'm pretty sure the expression 'rounded up' doesn't exist.

Anyways, hope I could help buddy! feel free to PM if you need help with a code or if the problem still isn't resolved. :emoji_relaxed:
 
Thanks for sending the full code, buddy. I've taken a look at it and tested it out myself. And saw that the problem likely lies here.


So these are the 2 problems that are likely to be present here.
  1. You can compare 2 objects but only under the condition that the values you compare are both the same type. Such as 2 dates or 2 timespans, but not a date and a timespan. Either in the first line or the second line I'm pretty sure that you could've tried to compare a timespan and a date, and that will return 'none', if it's an invalid comparison (=both objects are not the same type)
  2. The other problem you could possible have. In the first snippet of code that you sent, is that you tried to round the difference between 2 (probably) dates or timespans. Now, you can round the difference between 2 numbers, but not between 2 dates or timespan. Nor can you round an amount of time or date in general.
I'm suspecting problem 1 to likely be the problem here. because the way you saved {combatlog::%loop-player%::time} indicated at the end of the variable name, that it's a probably a time(span) and not a date. Btw the expression 'now' is a date and not an amount of time. '20 seconds' is an amount of time and not a date. What would be a date would be '20 seconds later', instead of just '20 seconds'

Another thing I wanted to mention is that I've never seen the expression 'rounded up' be used in skript. Is it a valid expression? I'm pretty sure, Skript has the built in function ceil() that would give the result that you wanted in that piece of code. and Skript also has the expression 'rounded', but after testing, I'm pretty sure the expression 'rounded up' doesn't exist.

Anyways, hope I could help buddy! feel free to PM if you need help with a code or if the problem still isn't resolved. :emoji_relaxed:
ty homie
 
Status
Not open for further replies.