-->
Page 1 of 1

Loop and array

PostPosted: Sat Feb 27, 2016 5:53 am
by tiawild
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

Re: Loop and array

PostPosted: Sun Feb 28, 2016 6:08 am
by Luc Volders
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

Re: Loop and array

PostPosted: Mon Feb 29, 2016 3:37 pm
by tiawild
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 :?