Lua not allowing global variables in a table

73 views Asked by At

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.

1

There are 1 answers

0
Some Dude On BEST ANSWER

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 in 0 as an argument. This was solved by simply changing it to 1 instead.