• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[solved] reverse contents of a list?

L

locklock

Guest
hello, apologies if this is really obvious, but how would I reverse the contents of a list?
 
L

locklock

Guest
it's a list of pathfinding nodes, and would make more intuitive sense to me if the nodes counted up. Is reversing a list bad form? The tutorial I'm reading is in python and uses list.reverse() without really commenting on it.
 
I can't think of a reason why reading the list in reverse order should be a problem, except that you'd probably need to keep track of an extra variable which is responsible for knowing whether you are currently going through the list forward or backward. If you must reverse the contents of the list, there isn't any built-in function to do this that I can see. So what you'll have to do is copy the contents of the list into another list, which will require you to read the first list in reverse order anyways.

ds_list_copy() ought to have an option to copy in reverse order (but doesn't).
 
L

locklock

Guest
ooooh, okay I've got it now. Just had to loop though the list backwards and copy it to a new one. Thank you, flying!
 
Top