Basically, the first time a file is loaded through ImportText, the dirs are mostly completely out of order. The second time, they are in loaded reverse order, which is fine and fixable.
I know savefile.dir in the reference says that the order is not necessary preserved - but clearly, it IS (as long as all the directories have an underscore), just not the first time it's loaded!
Numbered Steps to Reproduce Problem:
1. Download http://puu.sh/3lSlX.zip (It's a demo)
2. Run it.
3. Use the verb twice in the same instance of Dream Seeker.
4. Notice that the first set out of outputs is in the wrong order; while the second set is in the correct order. (Here's a sample of the outputs, separated by __)
In the demo, I output them backwards no matter what, so reverse order is expected and dealt with.
Code Snippet (if applicable) to Reproduce Problem:
The code in the demo is JUST this:
mob/verb/sagaFileTest()
var/savefile/sagaFile = new
sagaFile.ImportText("/", file2text("sagas.txt"))
var/accessSaga
for(var/x = sagaFile.dir.len to 1 step -1)
accessSaga = sagaFile.dir[x]
sagaFile.cd = accessSaga
world << "[accessSaga] = [sagaFile["name"]]"
sagaFile.cd = "/"
world << "__"
Expected Results:
Be in the same order no matter the amount of outputs.
Actual Results:
First output is in weird order. Second output is correct, but reversed from the directory order.
Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
No idea.
Workarounds:
Manually parse it yourself, or call it twice and waste time and resources like so:
sagaFileTest()
var/savefile/sagaFile = new
sagaFile.ImportText("/", file2text("Save/sagas.txt"))
sagaFile = new
sagaFile.ImportText("/", file2text("Save/sagas.txt"))
var/accessSaga
for(var/x = sagaFile.dir.len to 1 step -1)
accessSaga = sagaFile.dir[x]
sagaFile.cd = accessSaga
world << "[accessSaga] = [sagaFile["name"]]"
sagaFile.cd = "/"