ID:1837758
 
(See the best response by Lummox JR.)
Problem description:
Hello Folks,

I'm interested in making some code that allows players to build their own housing.
The approach I'd like to go for is to create small maps for player's houses and save that information along with the player's save file. An object or "portal" will be created on the actual map that allows players to access their map data.

My question is I'm a bit unfamiliar with how maps are saved, manipulated and loaded- I'd also like a basic run down of how to properly create a new z level of a map, and later dispose of it while it's not being used.

Note: I'm not looking for code or anything , just an explanation of the specifics so that I can formulate my own code or method to achieving these things.

The second question is- I ran across some code to change turfs on the fly, but it doesn't seem to work.

turf/proc/Change(new_type)
// replace turf with one of type newtype
var/turf/T = src
src = null
T = new(new_type,T) // replace T


///*
//Testing code/sample implementation:

turf/verb/change_turf(new_type in typesof(/turf)-/turf)
set src in oview(0)
src.Change(new_type)


Produces this error :

proc name: Change (/turf/proc/Change)
source file: Snippets.dm,221
usr: Avidanimefan (/mob/Nin)
src: null
call stack:
Change(/turf/house (/turf/house))
the dirt2 (24,60,15) (/turf/dirt2): change turf(/turf/house (/turf/house))

You're trying to set the turf to null, that's not gonna work. You really only have to create the new turf, it'll automatically replace the existing turf.
to replace a turf just do

new/turf/yourturf(theturfitsreplacing)
In response to Nadrew
Thanks. It's not my code though, it's actually in the snippets section of the website. Could someone fix it maybe?
Best response
The src=null line won't do you any harm, but it doesn't do any good, either. The only time you want to set src to null is if for some reason you want a proc to keep running after its original src is destroyed. (That still might not happen if its caller's src is destroyed.) When you replace turfs, you're not so much destroying them, so that's never a concern.

The new() call, as Nix pointed out, is wrong. (The sad part is, Spuzzum wrote that code. He was usually pretty good with code; must've been an off day.) If you have a new type in mind, the new() call would be:

new new_type(T)

Concerning map loading and saving, you'll want to look at SwapMaps or pif_MapLoader. However you may want to use only a subset of their contents, if the house is already built and the user can only alter the interior.

In response to Lummox JR
I ended up with this :
mob
verb
TestTurfChange()
for(var/turf/t in src.loc)
t.change_turf()

turf/proc/Change(new_type)
if(inta_change)
var/turf/t=new new_type(src) // replace T


I actually stumbled across SwapMaps and a few of FA's libs as well. I'll most likely try out SwapMaps, it seems like it has more control. Since I have a loose idea of what I want things may change. Thanks