Tuples
Lunaris supports tuples. A tuple is a small fixed group of values that belong together.
function GetLowestAndHighestNumber(input) {
local min = number.MaxValue
local max = number.MinValue
for (i in input) {
if (i < min) {
min = i
}
if (i > max) {
max = i
}
}
return (min, max)
}
local numbers = [9, 8, 4, 17]
local lowest, highest = GetLowestAndHighestNumber(numbers) // 4, 17
// The tuple can also be stored in a variable
local result = GetLowestAndHighestNumber(numbers)
print(result[0]) // 4
print(result[1]) // 17
A tuple is different from an array, as an array contains 0 or multiple entries, whereas a tuple is of a fixed size.
A tuple can also be declared as a variable
local position = (10, 20)
print(position[0]) // 10
print(position[1]) // 20
print(position[2]) // Error, as position only contains 2 items
Typing
Tuples also support optional typing
GetSpawnPosition() : (number, number) {
return (10, 20)
}