Current Lua downloadable firmware will be posted here

User avatar
By tiawild
#41990 Hi
I can't understand how I can set a value from an array in a loop.
This is my simplified code:
Code: Select allSequence = {7,1,2,3}

for count = 1, 4, 1 do
  print(Sequence[count])
  num = Sequence[count]
  print(num)
end

First function is OK instead second prints always a nil value. Why?
Thanks
User avatar
By Luc Volders
#42037 Just tried it and put it in Esplorer as a snippet.
Works as expected prints:

> Sequence = {7,1,2,3}
>
> for count = 1, 4, 1 do
>> --print(Sequence[count])
>> num = Sequence[count]
>> print(num)
>> end
7
1
2
3
>

Can't see a problem here
I commented out the first print statement. Before I did that it printed all values double as expected.

Luc
User avatar
By tiawild
#42124 Thank you Luc! ;)
As suggested I have tried it in Esplorer and it works properly.
The problem is that I have used it in LuaLoader and output is different:

Code: Select all7
nil
1
nil
2
nil
3
nil

I don't understand the reason :?