ID:146099
 
Code:
area
house
var
owner = "None"
hnum = 0
price = 50000
guest[]
house_1
hnum = 1
house_2
hnum = 2
price = 25000

var/housearea = list ()
world/Del()
..()
for(var/area/house/h in world)
if(istype(h,/area/house/))
housearea.Add(h)
F["housearea"] << housearea

Problem description:
I want to save and load an areas variables, and this is all I could think of but it does not work. I already have a system to save the objects in the area so that is not what I am trying to do. I am trying to save all the areas of type house and their variables.
Any ideas?
I have been thinking it over and maybe instead of saving the area just save the indivisual variables but I think that would lead to the same issue.
In response to Drumersl (#1)
world/
New()
..()
for(var/area/house/a in world)
var/savefile/F = new("houses/house_[a.hnum].sav")
F["owner"] >> a.owner
F["guests"] >> a.guest
F["price"] >> a.price
return ..()

Del()
for(var/area/house/a in world)
var/savefile/F = new("houses/house_[a.hnum].sav")
F["owner"] << a.owner
F["guests"] << a.guest
F["price"] << a.price
return ..()

Alright well I am now trying this method, but even though the areas vars are defined, it is saving them as null.
In response to Drumersl (#2)
I think you should be able to save the objects and their vars jsut by saying this :
F["Houses"]<< a

But also check to see if the file even exists before trying to load.
In response to Mecha Destroyer JD (#3)
That works for the objects, but i tried that for the areas themselves and it didnt work. It saved them as null.
In response to Drumersl (#4)
I think i figured it out!
Here is the code I used if anyone wants to know, or knows of a way to clean it up.
Area Code (not finished but good enough to work with the save/load system)
area
house
var
owner = "None"
hnum = 0
price = 50000
guest = list()
house_1
hnum = 1
house_2
hnum = 2
price = 25000
house_3
hnum = 3
house_4
hnum = 4
house_5
hnum = 5
house_6
hnum = 6
house_7
hnum = 7
house_8
hnum = 8
house_9
hnum = 9
house_10
hnum = 10



Load/Save Code
world/
New()
..()
for(var/area/house/a in world)
var/savefile/F = new("houses/house_[a.hnum].sav")
if(F["owner"])
F["owner"] >> a.owner
F["guests"] >> a.guest
F["price"] >> a.price
return ..()

Del()
..()
for(var/area/house/a in world)
var/savefile/F = new("houses/house_[a.hnum].sav")
F["owner"] << a.owner
F["guests"] << a.guest
F["price"] << a.price
return ..()


House Verbs
verb
Sell_House()
set category = "Actions"
switch(alert(usr,"Are you sure you want to sell your house for [src.price/2]?","Sell?","Yes","No"))
if("Yes")
switch(alert(usr,"You will lose everything left in your house, Ok?","","Yes","No"))
if("Yes")
usr.House = null
src.owner = "None"
usr.Gold += src.price/2
src.guest << null
return ..()
if("No")
return 0
if("No")
return 0
Transfer_House_Ownership(mob/m in world,price as num)
set category = "Actions"
if(m.client)
switch(alert(usr,"Are you sure you want to Transfer Ownership of your house for [price]?","Sell?","Yes","No"))
if("Yes")
switch(alert(usr,"You will lose everything left in your house, Ok?","","Yes","No"))
if("Yes")
switch(alert(m,"Are you sure you want to buy the house from [src.name] for [price]","","Yes","No"))
if("Yes")
if(m.Gold >= price)
usr.House = null
src.owner = m.ckey
src.guest << null
m.House = src.hnum
return ..()
else
m << "You do not have enough money"
usr << "Buyer does not have enough money"
if("No")
return 0
if("No")
return 0
if("No")
return 0
House_Invite(mob/m as mob in world)
set category = "Actions"
if(m.client)
if(usr.House)
if(istype(m,/mob))
m.HouseGuest += usr.House
var/path = text2path("/area/house/house_[usr.House]/guest")
path += m.ckey


Enter(mob/M)
if(istype(M,/obj))
return 1
if(istype(M,/mob))
if(src.owner == "None")
if(!M.House)
switch(alert(M,"Do you wish to buy this house for [src.price]?","Buy?","Yes","No"))
if("Yes")
if(M.Gold < src.price)
M << "Not enough gold!"
return 0
M<<"Welcome to your new house"
M.House = src.hnum
src.owner = M.ckey
M.Gold -= src.price
return ..()
if("No")
return 0
else return 0
else
if(src.owner)
if((M.ckey == src.owner && M.House == src.hnum) || M.Gm >= 4 || (M.ckey in src.guest && src.hnum in M.HouseGuest))
return ..()
else return 0
else return 0
else return 0

I wouldn't recomend using this code unless you fully understand it. Also because the code refers to procs/vars not defined in the code i showed.
In response to Drumersl (#5)
The code is pretty stretched. Look up the '&&' operator to trim the code down.