ID:1300083
 
Not a bug
BYOND Version:499
Operating System:Windows 7 Home Premium 64-bit
Web Browser:Chrome 29.0.1541.0
Applies to:Dream Daemon
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
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 = "/"
Lummox JR resolved issue (Not a bug)
If the reference says the order is not preserved, that means the order is completely arbitrary. It is not something that should be relied upon.
But it is preserved and not arbitrary, after the first time. If it works perfectly only on the second time import and so on, how is it not a bug? What could it possibly be doing differently between the first and second imports?
In response to Super Saiyan X
Super Saiyan X wrote:
But it is preserved and not arbitrary, after the first time. If it works perfectly only on the second time import and so on, how is it not a bug? What could it possibly be doing differently between the first and second imports?

The fact that the order stops changing doesn't make it any less arbitrary. The reference is telling you that the order is subject to change and not something you should ever rely on. Therefore the fact that it seems to stabilize after a while is irrelevant; you can't count on that stability, nor is its presence or absence at any given time a bug.