1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Rounding just fails.

Discussion in 'Skript' started by Jacob105, Mar 13, 2022.

Thread Status:
Not open for further replies.
  1. Jacob105

    Jacob105 Member

    Joined:
    Aug 7, 2020
    Messages:
    48
    Likes Received:
    1
    Code (Text):
    1.  
    2.             if {_combatElapsed} <= 20 seconds:
    3.                 set {_combat} to rounded up {_combat}
    4.                 set score "&r&7&m---------------------------" in sidebar of loop-player to 14
    5.                 set score "&b&lCooldowns" in sidebar of loop-player to 13
    6.                 set score " &3* &bCombat: &f%{_combat}%" in sidebar of loop-player to 12
    7.  
    (Combat and combat elapsed are supposed to be separate)
    Returns as <none>
    Any ideas on how to fix it?
    [​IMG]
     
  2. AFRICA1155

    AFRICA1155 New Member

    Joined:
    Mar 13, 2022
    Messages:
    9
    Likes Received:
    3
    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 (Text):
    1. function NumberAccuracy(n: number, a: number) :: text:
    2.     set {_amount} to rounded ({_n}*10^{_a})
    3.     if length of "%{_amount}%" is greater than {_a}:
    4.         set {_firstpart} to subtext of "%{_amount}%" from characters 1 to length of "%{_amount}%"-{_a}
    5.         set {_secondpart} to subtext of "%{_amount}%" from characters "%{_amount}%"'s length-{_a}+1 to length of "%{_amount}%"
    6.     else:
    7.         set {_firstpart} to 0      
    8.         set {_secondpart} to {_amount}
    9.     set {_n} to {_a}
    10.     remove length of "%{_secondpart}%" from {_n}
    11.     loop {_n} times:
    12.         set {_secondpart} to "0%{_secondpart}%"
    13.     loop {_a} times:
    14.         if last character of "%{_secondpart}%" is "0":
    15.             set {_secondpart} to subtext of "%{_secondpart}%" from characters 1 to length of "%{_secondpart}%"-1
    16.     if {_secondpart} is not set:
    17.         set {_return} to "%{_firstpart}%"
    18.     else:  
    19.         set {_return} to "%{_firstpart}%.%{_secondpart}%"
    20.     return "%{_return}%"
     
  3. Jacob105

    Jacob105 Member

    Joined:
    Aug 7, 2020
    Messages:
    48
    Likes Received:
    1
    Hey, thanks for your answer, it's a combat log timer, also it IS set.
    FULL CODE
    Code (Text):
    1. every tick:
    2.     loop all players:
    3.         wipe loop-player's sidebar
    4.         set name of sidebar of loop-player to "&b&lNitro&7 ┃ &3KitPVP &7(Alpha)"
    5.         set {_combatElapsed} to difference between now and {combatlog::%loop-player%::time}
    6.         set {_combat} to difference between 20 seconds and {_combatElapsed}
    7.         if {event} is "Combo":
    8.             if {_combatElapsed} <= 20 seconds:              
    9.                 set score "&r&7&m---------------------------" in sidebar of loop-player to 16
    10.                 set {_timeElapsed} to difference between {comboevent::timer} and now
    11.                 set score "&b&lEvents & Cooldowns" in sidebar of loop-player to 15
    12.                 set score " &3* &bEvent: &f%{event}%" in sidebar of loop-player to 14
    13.                 set score " &3* &bTime: &f%{_timeElapsed}%" in sidebar of loop-player to 13
    14.                 set score " &3* &bCombat: &f%{_combat}%" in sidebar of loop-player to 12
    15.                 set score " " in sidebar of loop-player to 11
    16.                 set score "&b&lYou" in sidebar of loop-player to 10
    17.                 if {levelcolored::%loop-player%} is not set:
    18.                     set {levelcolored::%loop-player%} to "&70"
    19.                 if {level::%loop-player%} is not set:
    20.                     set {level::%loop-player%} to 0
    21.                 if {XP::%loop-player%} is not set:
    22.                     set {XP::%loop-player%} to 0
    23.                 if {XPNeeded::%loop-player%} is not set:
    24.                     set {XPNeeded::%loop-player%} to 10
    25.                 set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
    26.                 if {kills::%loop-player%} is not set:
    27.                     set {kills::%loop-player%} to 0
    28.                 set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
    29.                 if {deaths::%loop-player%} is not set:
    30.                     set {deaths::%loop-player%} to 0
    31.                 set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
    32.                 if {killstreak::%loop-player%} is not set:
    33.                     set {killstreak::%loop-player%} to 0
    34.                 if {bestkillstreak::%loop-player%} is not set:
    35.                     set {bestkillstreak::%loop-player%} to 0
    36.                 set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
    37.                 if {KDR::%loop-player%} is not set:
    38.                     set {KDR::%loop-player%} to 0
    39.                 set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
    40.                 if {beloved::%loop-player%} is not set:
    41.                     set {beloved::%loop-player%} to 0
    42.                 set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
    43.                 if {balance::%loop-player%} is not set:
    44.                     set {balance::%loop-player%} to "0.00"
    45.                 set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
    46.                 set score "&7&m---------------------------&r" in sidebar of loop-player to 1
    47.             else:
    48.                 set score "&r&7&m---------------------------" in sidebar of loop-player to 15
    49.                 set {_timeElapsed} to difference between {comboevent::timer} and now
    50.                 set score "&b&lEvents" in sidebar of loop-player to 14
    51.                 set score " &3* &bEvent: &f%{event}%" in sidebar of loop-player to 13
    52.                 set score " &3* &bTime: &f%{_timeElapsed}%" in sidebar of loop-player to 12
    53.                 set score " " in sidebar of loop-player to 11
    54.                 set score "&b&lYou" in sidebar of loop-player to 10
    55.                 if {levelcolored::%loop-player%} is not set:
    56.                     set {levelcolored::%loop-player%} to "&70"
    57.                 if {level::%loop-player%} is not set:
    58.                     set {level::%loop-player%} to 0
    59.                 if {XP::%loop-player%} is not set:
    60.                     set {XP::%loop-player%} to 0
    61.                 if {XPNeeded::%loop-player%} is not set:
    62.                     set {XPNeeded::%loop-player%} to 10
    63.                 set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
    64.                 if {kills::%loop-player%} is not set:
    65.                     set {kills::%loop-player%} to 0
    66.                 set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
    67.                 if {deaths::%loop-player%} is not set:
    68.                     set {deaths::%loop-player%} to 0
    69.                 set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
    70.                 if {killstreak::%loop-player%} is not set:
    71.                     set {killstreak::%loop-player%} to 0
    72.                 if {bestkillstreak::%loop-player%} is not set:
    73.                     set {bestkillstreak::%loop-player%} to 0
    74.                 set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
    75.                 if {KDR::%loop-player%} is not set:
    76.                     set {KDR::%loop-player%} to 0
    77.                 set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
    78.                 if {beloved::%loop-player%} is not set:
    79.                     set {beloved::%loop-player%} to 0
    80.                 set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
    81.                 if {balance::%loop-player%} is not set:
    82.                     set {balance::%loop-player%} to "0.00"
    83.                 set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
    84.                 set score "&7&m---------------------------&r" in sidebar of loop-player to 1
    85.         else if {event} is "Target":
    86.             if {_combatElapsed} <= 20 seconds:              
    87.                 set score "&r&7&m---------------------------" in sidebar of loop-player to 17
    88.                 set {_timeElapsed} to difference between {targetevent::timer} and now
    89.                 set score "&b&lEvents & Cooldowns" in sidebar of loop-player to 16
    90.                 set score " &3* &bEvent: &f%{event}%" in sidebar of loop-player to 15
    91.                 set score " &3* &bTarget: &f%{thetarget}%" in sidebar of loop-player to 14
    92.                 set score " &3* &bTime: &f%{_timeElapsed}%" in sidebar of loop-player to 13
    93.                 set score " &3* &bCombat: &f%{_combat}%" in sidebar of loop-player to 12
    94.                 set score " " in sidebar of loop-player to 11
    95.                 set score "&b&lYou" in sidebar of loop-player to 10
    96.                 if {levelcolored::%loop-player%} is not set:
    97.                     set {levelcolored::%loop-player%} to "&70"
    98.                 if {level::%loop-player%} is not set:
    99.                     set {level::%loop-player%} to 0
    100.                 if {XP::%loop-player%} is not set:
    101.                     set {XP::%loop-player%} to 0
    102.                 if {XPNeeded::%loop-player%} is not set:
    103.                     set {XPNeeded::%loop-player%} to 10
    104.                 set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
    105.                 if {kills::%loop-player%} is not set:
    106.                     set {kills::%loop-player%} to 0
    107.                 set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
    108.                 if {deaths::%loop-player%} is not set:
    109.                     set {deaths::%loop-player%} to 0
    110.                 set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
    111.                 if {killstreak::%loop-player%} is not set:
    112.                     set {killstreak::%loop-player%} to 0
    113.                 if {bestkillstreak::%loop-player%} is not set:
    114.                     set {bestkillstreak::%loop-player%} to 0
    115.                 set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
    116.                 if {KDR::%loop-player%} is not set:
    117.                     set {KDR::%loop-player%} to 0
    118.                 set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
    119.                 if {beloved::%loop-player%} is not set:
    120.                     set {beloved::%loop-player%} to 0
    121.                 set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
    122.                 if {balance::%loop-player%} is not set:
    123.                     set {balance::%loop-player%} to "0.00"
    124.                 set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
    125.                 set score "&7&m---------------------------&r" in sidebar of loop-player to 1
    126.             else:
    127.                 set {_timeElapsed} to difference between {targetevent::timer} and now
    128.                 set score "&r&7&m---------------------------" in sidebar of loop-player to 16
    129.                 set score "&b&lEvents" in sidebar of loop-player to 15
    130.                 set score " &3* &bEvent: &f%{event}%" in sidebar of loop-player to 14
    131.                 set score " &3* &bTarget: &f%{thetarget}%" in sidebar of loop-player to 13
    132.                 set score " &3* &bTime: &f%{_timeElapsed}%" in sidebar of loop-player to 12
    133.                 set score " " in sidebar of loop-player to 11
    134.                 set score "&b&lYou" in sidebar of loop-player to 10
    135.                 if {level::%loop-player%} is not set:
    136.                     set {level::%loop-player%} to 0
    137.                 if {levelcolored::%loop-player%} is not set:
    138.                     set {levelcolored::%loop-player%} to "&70"
    139.                 if {XP::%loop-player%} is not set:
    140.                     set {XP::%loop-player%} to 0
    141.                 if {XPNeeded::%loop-player%} is not set:
    142.                     set {XPNeeded::%loop-player%} to 10
    143.                 set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
    144.                 if {kills::%loop-player%} is not set:
    145.                     set {kills::%loop-player%} to 0
    146.                 set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
    147.                 if {deaths::%loop-player%} is not set:
    148.                     set {deaths::%loop-player%} to 0
    149.                 set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
    150.                 if {killstreak::%loop-player%} is not set:
    151.                     set {killstreak::%loop-player%} to 0
    152.                 if {bestkillstreak::%loop-player%} is not set:
    153.                     set {bestkillstreak::%loop-player%} to 0
    154.                 set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
    155.                 if {KDR::%loop-player%} is not set:
    156.                     set {KDR::%loop-player%} to 0
    157.                 set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
    158.                 if {beloved::%loop-player%} is not set:
    159.                     set {beloved::%loop-player%} to 0
    160.                 set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
    161.                 if {balance::%loop-player%} is not set:
    162.                     set {balance::%loop-player%} to "0.00"
    163.                 set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
    164.                 set score "&7&m---------------------------&r" in sidebar of loop-player to 1
    165.         else:
    166.             if {_combatElapsed} <= 20 seconds:              
    167.                 set score "&r&7&m---------------------------" in sidebar of loop-player to 14
    168.                 set score "&b&lCooldowns" in sidebar of loop-player to 13
    169.                 set score " &3* &bCombat: &f%{_combat}%" in sidebar of loop-player to 12
    170.                 set score " " in sidebar of loop-player to 11
    171.             else:
    172.                 set score "&r&7&m---------------------------" in sidebar of loop-player to 11
    173.             set score "&b&lYou" in sidebar of loop-player to 10
    174.             if {level::%loop-player%} is not set:
    175.                 set {level::%loop-player%} to 0
    176.             if {levelcolored::%loop-player%} is not set:
    177.                 set {levelcolored::%loop-player%} to "&70"
    178.             if {XP::%loop-player%} is not set:
    179.                 set {XP::%loop-player%} to 0
    180.             if {XPNeeded::%loop-player%} is not set:
    181.                 set {XPNeeded::%loop-player%} to 10
    182.             set score " &3* &bLevel: &f%{levelcolored::%loop-player%}% &7(%{XP::%loop-player%}%/%{XPNeeded::%loop-player%}%)" in sidebar of loop-player to 9
    183.             if {kills::%loop-player%} is not set:
    184.                 set {kills::%loop-player%} to 0
    185.             set score " &3* &bKills: &f%{kills::%loop-player%}%" in sidebar of loop-player to 8
    186.             if {deaths::%loop-player%} is not set:
    187.                 set {deaths::%loop-player%} to 0
    188.             set score " &3* &bDeaths: &f%{deaths::%loop-player%}%" in sidebar of loop-player to 7
    189.             if {killstreak::%loop-player%} is not set:
    190.                 set {killstreak::%loop-player%} to 0
    191.             if {bestkillstreak::%loop-player%} is not set:
    192.                 set {bestkillstreak::%loop-player%} to 0
    193.             set score " &3* &bKillstreak: &f%{killstreak::%loop-player%}% &7(%{bestkillstreak::%loop-player%}%)" in sidebar of loop-player to 6
    194.             if {KDR::%loop-player%} is not set:
    195.                 set {KDR::%loop-player%} to 0
    196.             set score " &3* &bKDR: &f%{KDR::%loop-player%}%" in sidebar of loop-player to 5
    197.             if {beloved::%loop-player%} is not set:
    198.                 set {beloved::%loop-player%} to 0
    199.             set score " &3* &bBeloveds: &f%{beloved::%loop-player%}%" in sidebar of loop-player to 4
    200.             if {balance::%loop-player%} is not set:
    201.                 set {balance::%loop-player%} to "0.00"
    202.             set score " &3* &bBalance: &f$%{balance::%loop-player%}%" in sidebar of loop-player to 3
    203.             set score "&7&m---------------------------&r" in sidebar of loop-player to 1
     
  4. AFRICA1155

    AFRICA1155 New Member

    Joined:
    Mar 13, 2022
    Messages:
    9
    Likes Received:
    3
    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:
     
  5. Jacob105

    Jacob105 Member

    Joined:
    Aug 7, 2020
    Messages:
    48
    Likes Received:
    1
    ty homie
     
Thread Status:
Not open for further replies.

Share This Page

Loading...