# 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 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.

#1
2. Best Answer:
Post #2 by Nikd0, Feb 22, 2021
3. ### 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

#2
• Useful x 1
4. ### DeadlySkyLord Member

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

#3
Thread Status:
Not open for further replies.

• ### About Us

Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.
• ### Support skUnity

The staff team works very hard to make sure the community is running its best. This means constantly performing upgrades to systems and other features. This does cost a bit of money to keep doing. Donating to skUnity would allow the server to keep running smoothly for years to come!

Support Us!
• ### Join our Discord

Discord is an all-in-one voice and text chat for gamers thatâ€™s free, secure, and works on both your desktop and phone.