# Solved How do I get all integers between two numbers

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

Not open for further replies.

Joined:
May 23, 2020
Messages:
11
0
Hi, I would like to know how to get all integers between two numbers. Thanks.

#1
Post #2 by Nikd0, Feb 22, 2021
3. ### Nikd0 Active Member

Joined:
May 30, 2020
Messages:
204
19
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}%"
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

#2
• Useful x 1

Joined:
May 23, 2020
Messages:
11
0
Thanks!

#3
Not open for further replies.