7
Beginner
AZSTOKe_sample_tableMaxn
Print length of array
RANK
function Msg(param)
reaper.ShowConsoleMsg(tostring(param).."\n")
end
function table.maxn( table )
local maxn, k = 0, nil
repeat
k = next( table, k )
if type( k ) == 'number' and k > maxn then
maxn = k
end
until not k
return maxn
end
a = {"a","b","c"}
x = table.maxn(a)
Msg(x)
function Msg(param)
reaper.ShowConsoleMsg(tostring(param).."\n")
end
Set Msg console output function
function table.maxn( table )
Define a function to find the maximum value of an array
local maxn, k = 0, nil
Define variables for storing maximum value and array value.
repeat
k = next( table, k )
if type( k ) == 'number' and k > maxn then
maxn = k
end
until not k
Get index value from array. If the obtained value can be converted into a numerical value and is larger than the provisional maximum value, the obtained value is set as the provisional maximum value. Repeat this process from the beginning to the end of the array.
return maxn
Returns the provisional maximum value as the final maximum value.
a = {"a","b","c"}
x = table.maxn(a)
To use the API, you need to sign up for a plan.
Download the dedicated API
need to do it.
*SILVER is scheduled to be released in May.
No preparation required