Bang: [!CommandMeasure Lua "loadArray(1)"]
Lua:
Code: Select all
1Array = {0}
loadArray(num)
print(num..Array[0])
end
Code: Select all
1Array = {0}
loadArray(num)
print(num..Array[0])
end
In lua the indices of arrays by default are starting from 1, not from 0. So the above print function should be print(num..Array[1]), in order to get concatenated the num variable with the first element of the Array array.Jax wrote: ↑August 15th, 2021, 9:47 am I wanted to make it so that I can get the array by passing a number in a function.
Bang: [!CommandMeasure Lua "loadArray(1)"]
Lua:Code: Select all
1Array = {0} loadArray(num) print(num..Array[0]) end
I see...
You can't... It's a variable so it should be accessed by name only.
Code: Select all
local mainArray={}
mainArray["subArray1"]={'cat', 'dog'}
mainArray["subArray2"]={'crow', 'pigeon'}
Code: Select all
!CommandMeasure Lua "print(mainArray['subArray'..'#NumberVariable#'][1])"
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
[MeasureLoop]
Measure=Loop
StartValue=1
EndValue=4
[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1
[MeterOutput]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[&Lua:Lookup([&MeasureLoop:])]
DynamicVariables=1
Code: Select all
function Initialize()
tableLookup = {'one banana','two banana','three banana', 'four'}
end
function Lookup(indexArg)
return tableLookup[indexArg]
end
Code: Select all
function Initialize()
tableLookup = {'one banana','two banana','three banana', 'four'}
end
function Lookup(indexArg)
if indexArg > #tableLookup or indexArg < 1 then
return 'Out of range!'
else
return tableLookup[indexArg]
end
end
Code: Select all
print(unpack{10,20,30})