Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to loop in reverse using an alternative to ipairs?

Asked by
Ribasu 127
5 years ago
Edited 5 years ago

Take a look at the following code sample which loops through a simple list:

myList = {1,2,3}
for i,v in ipairs(myList) do
    print(`v)
end

this outputs: 1 , 2 and 3. the reverse order print of this would be 3, 2, 1.

Is it possible, in LUA, to get the reversed output WITHOUT reversing myList and without using for i, #myList doloop? Is there a reverseIPairs()function or something like that?

0
something like this? https://gist.github.com/balaam/3122129 User#20388 0 — 5y
0
No... that is reversing the waypoints and then looping over this same reversed set. I don't want to reverse my waypoints, I want to access them in a reverse order... The difference is in the first approach you need to reverse, then go over each element, and in the second, you don't need to reverse - you just iterate in reverse order - so more efficient. Ribasu 127 — 5y
0
I don't rlly see the problem, it all happends so fast you wouldn't notice the difference User#20388 0 — 5y
0
I have a very very very big list... :( Ribasu 127 — 5y
0
dang XxOPGUYxX1234567 221 — 3y

Answer this question