ID:148194
 
Ok, my procs fo saving are a bit..as to say "ODD".
They'll work one time, then not another...any idea why this is happening? It ONLY Loads the cars when I have NPC cars marked as "purchased=1" for some reason when it's 0, it doesn't want to load.

proc
SaveCars()
var/savefile/cars=new/savefile("cars.sav")
var/carNum=0
var/mobcount=0
for(var/mob/vehicles/C in world.contents)
if(C.purchased==1)
cars["car[carNum]"]<<C //save each car individually
carNum++
mobcount++
cars["carNum"]<<carNum //save the total number of cars
world<<"[mobcount] car\s saved!"
proc
LoadCars()
var/savefile/cars=new/savefile("cars.sav")
var/carNum=0
var/mobcount=0
cars["carNum"]>>carNum
if(carNum)
for(var/i=1 to carNum)
var/mob/vehicles/newCar
cars["car[i]"]>>newCar
world<<"[newCar.x],[newCar.y],[newCar.z]"//DEBUG Message
mobcount++
world<<"[mobcount] car\s loaded!"

I get this run-time from my debug message:

runtime error: Cannot read null.x
proc name: LoadCars (/proc/LoadCars)
source file: procs.dm,20
usr: null
src: null
call stack:
LoadCars()
: New()
</<carnum></<c>
Problem: You're saving your cars wrong.
cars["car[carNum]"]<<C //save each car individually
carNum++
mobcount++
The first car saved is "car0", and the last is "car[carNum-1]", because you started off carNum at 0 and only increase it after saving. The correct solution is to increment carNum before saving:
cars["car[++carNum]"] << C
++mobcount
You could just move the carNum++ line above the one before it, but it makes more sense to just combine them. When combining them, it's important that you use ++carNum instead of carNum++ so carNum is incremented before it becomes part of the name, not after.

Lummox JR
In response to Lummox JR
WEHE! Thank you Lummox, it has worked like a charm! I'll be sure to include you in the thanks and the credits! Along with all the others who have helped me!