I have some code in Lua:
math.randomseed(os.time())
amount = 0 --math.random(0, 54000)
bgItem = mediaPool:AppendToTimeline({ {
mediaPoolItem = clip[1],
trackIndex = 1,
recordFrame = 216000,
startFrame = amount,
endFrame = amount+total,
mediaType = 1
} })[1]
Having amount
as 0
works perfectly fine, but when I set it to math.random(0, 54000)
it gives an error: attempt to perform arithmetic on field 'amount' (a nil value)
. I am extremely confused as to why it works differently when it's set normally and when it's set by the output of a function.
Thanks to koyaanisqatsi for the comment, the issue lied in the specific function I was using to get a random number. Lua's
math.random()
function cannot take in0
as an argument. This was solved by simply changing it to1
instead.