ID:176581
 
Hello,
I was looking through the byond folders on my cousins computer and i found Lummox Jr's incursion folder. Inside was a text file with variables such as adminlist and stuff. I was wondering how this was done. My coding skills are not all that good, but i thought it had sumthing to do with text2file and file2text. Can you help?
[Edit]
Also when you are saving a mob can u only have the savefile type as .sav?

Thanks in advance
Not to be rude but....Bump.
Weedman wrote:
Hello,
I was looking through the byond folders on my cousins computer and i found Lummox Jr's incursion folder. Inside was a text file with variables such as adminlist and stuff. I was wondering how this was done. My coding skills are not all that good, but i thought it had sumthing to do with text2file and file2text. Can you help?

I used savefile.Export() and Import() for this. The file is deliberately stored in text format so if all else fails it can be edited outside of the game.

Lummox JR
In response to Lummox JR
Thank you very much. I see how it is done but i have another question. How will i save a list such as a list of admins.lets call it adminlist.
now i tried doing this by just doing
F["adminlist"] << adminlist

and it returned sumthing like this in the text file

adminlist = "MeYouHimHerIt"

now how will i make it save so the result looks sumthing like

adminlist = list("Me","You","He","She","It")
In response to Weedman
Weedman wrote:
Thank you very much. I see how it is done but i have another question. How will i save a list such as a list of admins.lets call it adminlist.
now i tried doing this by just doing
F["adminlist"] << adminlist

and it returned sumthing like this in the text file

adminlist = "MeYouHimHerIt"

now how will i make it save so the result looks sumthing like

adminlist = list("Me","You","He","She","It")

Hrm. Can I see the code you're using to set up the original adminlist? If this last line were done before the save line, then it should indeed be saving as a list.

Lummox JR
In response to Lummox JR
I was lookig at the exporttext var in the DM Help file and there was a string of code attached to it as an example, so i decided to use it.

Here it is:

var
list/adminlist = list()
//and some random vars i made up for testing
time
kills
deaths

world/New()
..()
read()
world/Del()
write()
..()
proc/write()
var/savefile/F = new()
var/txtfile = file("world/config.txt")
time += world.time
F["adminlist"] << adminlist //<-- is it because im saving a list like this?
F["time"] << time
F["kills"] << kills
F["deaths"] << deaths

fdel(txtfile)
F.ExportText("/",txtfile)

proc/read()
var/savefile/F = new()
var/txtfile = file("world/config.txt")

F.ImportText("/",txtfile)

F["adminlist"] >> adminlist
F["time"] >> time
F["kills"] >> kills
F["deaths"] >> deaths

//and when i was testing i just add random names to the list
mob/host/verb
AddAdmin(t as text)
adminlist += t
world << "[t] is now an admin"
In response to Weedman
I think I see the problem, and it's fairly insidious, so it's not surprising you didn't spot it.

Basically you're doing everything right; the list is initialized properly, and everything's going along great. However, I kept skipping my eyes back to the AddAdmin verb:
mob/host/verb
AddAdmin(t as text)
adminlist += t
world << "[t] is now an admin"
It's the += that got my attention; this should be working with a list, and you did in fact initialize adminlist as list(). Yet somehow the game is treating adminlist like a text string at some point, because as you start adding to it it just appends to the string, as you showed me. So something, somewhere, is changing adminlist to something that would be treated as text in the verb.

Then it hit me:
world/New()
..()
read()

proc/read()
var/savefile/F = new()
var/txtfile = file("world/config.txt")

F.ImportText("/",txtfile)

F["adminlist"] >> adminlist
F["time"] >> time
F["kills"] >> kills
F["deaths"] >> deaths
It's the line that loads adminlist from the file when you start the world; this is what's changing it.

When the list is loaded, it's loading as null if you have no file. When += is used on it, the game thinks you want to add text to a blank string, so it becomes a text string matching the first name you put in; the next name you put in gets tacked onto the end of that, because it now thinks adminlist is a string.

As you can see this is very, very subtle. The solution to your problem is to add another line after loading the list:
    F["adminlist"] >> adminlist
if(!adminlist || !istype(adminlist,/list)) adminlist=new
That will create a brand new list if the list you just loaded happens not to be there.

Alternatively, you can change your AddAdmin verb to re-initialize the list there if it doesn't exist:
mob/host/verb
AddAdmin(t as text)
if(!adminlist || !istype(adminlist,/list)) adminlist=new
adminlist += t
world << "[t] is now an admin"
Either of those should fix your problem.

Lummox JR
In response to Lummox JR
It works! :-D
Thank you very much Lummox.
In response to Lummox JR
couldn't you just do

adminlist.Add(t)?
In response to Hazman
Hazman wrote:
couldn't you just do

adminlist.Add(t)?

That would do the same thing as +=, but with one critical difference: It would actually show up the error of a null list.
As a matter of style I much prefer += anyway, though.

Lummox JR