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.

Solved How do I get all integers between two numbers

Discussion in 'Skript' started by DeadlySkyLord, Feb 21, 2021.

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

    DeadlySkyLord Member

    Joined:
    May 23, 2020
    Messages:
    11
    Likes Received:
    0
    Hi, I would like to know how to get all integers between two numbers. Thanks.
     
  2. Best Answer:
    Post #2 by Nikd0, Feb 22, 2021
  3. Nikd0

    Nikd0 Active Member

    Joined:
    May 30, 2020
    Messages:
    206
    Likes Received:
    20
    A maths lesson: There is a infinite amount of numbers between two selected ones. Therefore, I assume you wanted integers
    Code (Text):
    1.  
    2. function betweenInts(a: integer, b: integer) :: text: #assuming that b > a
    3.     set {_nmb} to {_a} +1
    4.     while {_nmb} < {_b}:
    5.         if {_result} is not set:
    6.             set {_result} to "%{_nmb}%"
    7.         else:
    8.             set {_result} to "%{_result}%,%{_nmb}%"
    9.         add 1 to {_nmb}
    10.     return {_result}
    11.  
    Created a rather simple function that returns text, but you may want it as an array (i did not find a way how to return an array).
    You can do it inside your command, for instance:
    Code (Text):
    1.  
    2. command /test <integer> <integer>:
    3.     trigger:
    4.         set {_x} to betweenInts(arg-1, arg-2)
    5.         set {_end::*} to {_x} split at ","
    6.         broadcast "%{_end::*}%" #or do whatever you want to do with it
    7.  
    Example of use: /test 1 6 (returns 2, 3, 4 and 5)
    Note: I tested it, it works.

    If I helped you, consider liking my message, marking the thread as solved and also choosing my answer as the best one :emoji_wink:
     
    • Useful Useful x 1
  4. DeadlySkyLord

    DeadlySkyLord Member

    Joined:
    May 23, 2020
    Messages:
    11
    Likes Received:
    0
Thread Status:
Not open for further replies.

Share This Page

Loading...