ID:156224
 
For my game, a player can successfully buy a house. Now, I'm trying to add editable furniture. How do I make a saving script that saves where the furniture is placed when a reboot is executed, so that when the reboot is done, the furniture is still there?
var/savefile/F = new("furniture.sav")
Write(F)



Then whenever you need to load it, put Read code in a reboot or anywhere else you want to, so that it can be loaded.
In response to Hashir
Never EVER call write like that, it will bug the "Read".
In response to Hashir
@ Hashir :
That doesn't help the OP, for the most part.
You don't generally want to use Write() and Read(), and instead << the variables/objects.

@ Colin1011 :
What you'll most likely want to do is loop through the objects and add them to a list so that you can save the list like so:

obj/furniture
{
var savedX
var savedY
var savedZ
blue_chair // This is a blue chair.
welcome_mat // This is a welcome mat.
// etc. etc.
}

proc/saveFurniture()
{
var savefile/saveFile = new("mapSave/savedFurniture.sav")
var list/savedObjects = list()
for (var/obj/furniture/object in world)
{
object.savedX = object.x
object.savedY = object.y
object.savedZ = object.z
savedObjects += object
}
saveFile["savedObjects"] << savedObjects
}

proc/loadFurniture()
{
if (fexists("mapSave/savedFurniture.sav"))
{
var savefile/saveFile = new("mapSave/savedFurniture.sav")
var list/loadedObjects = list()
saveFile["savedObjects"] >> loadedObjects
for (var/obj/furniture/object in loadedObjects)
{
object.x = object.savedX
object.y = object.savedY
object.z = object.savedZ
}
}
}
In response to Maximus_Alex2003
They still just disappear... this is where I call those procs you wrote up.
mob
Login()
if(fexists("[ckey].sav"))
world<<"<font color = purple>[src.key] has logged in!"
icon='ICONS.dmi'
src.frozen=0
src<<"Welcome to Age of Shadow!"
src.punchcooldown=0
src.titles+="Reset"
src.Load()
loadFurniture()

and
    Logout()
if(src.instart==1)
var/obj/Z=locate(/obj/holder)in world
Z.hold=0
src.instart=0
src.vree+=src.vars
for(var/obj/A as obj in world)
A.vree+=A.vars
src.overlays=null
src.Save()
saveFurniture()
world<<"<font color = purple>[src.key] has logged out."
del(src)
In response to Colin1011
You've given us no background on how furniture actually exists in your game, so it's pretty hard to say where the problem is.
In response to Colin1011
Those procedures weren't /mob related, since /mob is terrible to base procedures with, since they aren't players. Plus, you specifically asked for when the world is rebooted, hence why they are global procedures.
In response to Pirion
Pirion wrote:
Never EVER call write like that, it will bug the "Read".

How do you call it?
In response to Falacy
savefile operator <<

F << Val
F["Path"] << Val
In response to Pirion
That doesn't really have anything to do with Read or Write, that's a method for more manually saving things
In response to Falacy
Calling Read() and Write() directly can result in mangled savefiles in certain circumstances. >> and << cannot.