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.

Loop value problem

Discussion in 'Skript' started by KroterPvP, Mar 30, 2018.

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

    KroterPvP Active Member

    Joined:
    Apr 10, 2017
    Messages:
    178
    Likes Received:
    7
    Hi, I'm trying to asign a value to 100 variables. The values are:
    Code (Skript):
    1. {levels::0} = 0
    2. {levels::1} = 10
    3. {levels::2} = 20
    4. ...
    5. {levels::10} = 100
    6. ...
    7. {levels::30} = 300
    8. ...
    9. {levels::50} = 500
    10. ...
    11. {levels::100} = 1000
    Code (Skript):
    1. on load:
    2.     delete {levels::*} # I'm debugging so I reset the variable.
    3.     if {levels::*} is not set: # It will never be set because it deletes it.
    4.         set {levels::0} to 0
    5.         loop 10 times:
    6.             add 10 to {levels::%loop-number - 1%}
    7.             send "%loop-number - 1%, %{levels::%loop-number - 1%}%"
    No console errors.

    The %loop-number - 1% variable works but the %{levels::%loop-number - 1%}% is always displayed as 10. Why?
     
  2. Lego_freak1999

    Lego_freak1999 Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    664
    Likes Received:
    45
    Errors? Whats THE problem explain better?
     
  3. KroterPvP

    KroterPvP Active Member

    Joined:
    Apr 10, 2017
    Messages:
    178
    Likes Received:
    7
    Sorry, post edited. The problem: The %loop-number - 1% variable works but the %{levels::%loop-number - 1%}% is always displayed as 10. Why?
     
  4. Lego_freak1999

    Lego_freak1999 Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    664
    Likes Received:
    45
    give me a moment Will send a code
     
  5. KroterPvP

    KroterPvP Active Member

    Joined:
    Apr 10, 2017
    Messages:
    178
    Likes Received:
    7
    okey
     
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    The problem is....
    You're only ever adding 10 to your variable
    "add 10 to {levels::%loop-number - 1%}"
     
  7. KroterPvP

    KroterPvP Active Member

    Joined:
    Apr 10, 2017
    Messages:
    178
    Likes Received:
    7
    Oh my god, you'r right!
    I was adding "10" to a different variable...

    Solution:
    Code (Skript):
    1. on load:
    2.     delete {levels::*}
    3.     if {levels::*} is not set:
    4.         set {levels::0} to 0
    5.         loop 10 times:
    6.             set {levels::%loop-number - 1%} to ({levels::%loop-number - 2%} + 10)
    7.             send "%loop-number - 1%, %{levels::%loop-number - 1%}%" to players
     
    • Like Like x 1
Thread Status:
Not open for further replies.

Share This Page

Loading...