ID:2075282
 
(See the best response by Kaiochao.)
Code:


Problem description:I want to read plain text .txt files but don't know how to do this. Ill tell ya why I want to do this is so I load little things quick with out using the .sav files that cant be opened in notepad. Ill give an example.

I want to read through a file that has a long list of saved npcs. This is just a little example of what the text file would contain.

Begin List
npc 1
type /mob/npc/questboss
name "Boss 1"
x 123
y 78
z 1
npc 2
type /mob/npc/questboss
name "Boss 2"
x 157
y 33
z 1
End List

They are the same type but I want to be able to see what they are by reading a simple list and changing it in notepad. how would you go about reading that textfile and setting the location, and name of these questbosses when the world loads.

Best response
It might help to use file2text() and splittext(). For example:
var text = file2text("text file.txt")

// \n is the newline character, so this splits the text into lines
var lines[] = splittext(text, "\n")

for(var/n in 1 to lines.len)
src << "Line [n]: [lines[n]]"

// then you might splittext() again with space as the separator

Or you could learn JSON, write your text file in JSON, and use json_decode().
{
"npc 1": {
"type": "/mob/npc/questboss",
"name": "Boss 1",
"x": 123
},
"npc 2": {
"type": "/mob/npc/questboss",

}

etc.
Thanks so much Kaiochao, you made my life easier bud.