(See the best response by Lummox JR.)
Okay, I have a lot of really rigged code that I would love to get help with. Since there is a number of issues I have I will start first with this concept I am coding. Okay there is a game with map squares like Zelda 1 for NES that I am coding. It is procedurally generated but it saves as a permanent part of the world once it is initially created. so if I start at x:100, y:100 overland map and it is 20x20 tile screens lets say my only idea is to have a each square area and load into like a 4 dimension variable mapx, mapy, turfx, turfy and save the world to a file or something. I don't know how to do multi dimensional variables yet on BYOND or whether that is even a good option above making a different file for every area and just loading it on enter. Please post your thoughts and suggestions I seem to be able to get a lot done with very rough code, but this one has me a little stumped.

What are mapx, mapy, turfx and turfy suppose to represent? Are you talking about pixel movement? Like - Calculating a location of an object within a 20x20 tile?

I can't speak for the rest of the community, but I definitely know that I would need to see some code and if possible have you be more precise on what exactly you're looking for before I could be of assistance. Cheers.
I'm totally not using the in between measurements everything is 32x32px icons so only movement will have to mess with those, but not my mapping system.

Okay let's say your playing Zelda 1 for Nintendo entertainment system. You start out at that area that has an entrance to the cave where you go in and get your first sword.

In my world This starting map would be x=100,y=100 position on the big overhead map which doesn't visually exist it just is to keep track of world position. This map just like all the others and is 20 x 20 turf size. So my theory is that I will generate each map as you enter it using a ton of different rule systems and marching squares procedural generation theory and when it is complete it is permanently part of the world.

So what I'm asking is if the following below would be the way to handle that of course the only thing I didn't include below is the rules for procedurally generating the 20x20 map as you walk off the edge of the last one and the new one pops up. In short the whole world only uses one map file and generates all the turfs from a variable that it creates when you first enter and after that it loads to variable when world begins and saves to file when world ends.

i.e. whole world is a multi dimensional variable array or "list" as byond calls it.

Am I on the right track?

Only way I know how to do this is with a 2 at the end one for type and the other for icon state.

/var/worldmap = new /list(200,200,20,20,2)
//above is worldx, worldy, turfx, turfy,
//1=type, 2=icon_state

var/worldmap_sav = "worldmap.sav"
var/savefile/F = new(worldmap_sav)
F >> worldmap //load map into variable
return ..()

var/worldmap_sav = "worldmap.sav"
var/savefile/F = new(worldmap_sav)
F << worldmap //save existing world map
return ..()

Thank you anyone replying for dealing with my barbaric way of explaining things.
I'm still not sure what you're driving at, or even why you're using a list instead of loading and saving individual values. Or better yet, a datum. A datum sounds much closer to what you want.

About multidimensional lists: they're really not good solutions to just about any problem. A multidimensional list is a list of lists; it's unwieldy and you'll usually do two lookups where one lookup and a small amount of math would have been easier.
Thank you for your reply I'm sorry about being so confusing, but I really don't know the proper way to code anything I just duct tape it until it functions.

So what I'm trying to do here is create a 20x20 turf map using code to select what turfs go where. So after that map is generated and your character is walking around in it when you walk to the edge of the map it goes to a new map which is also generated from code by simply moving you on the opposite side of the map and replacing all the turfs. The whole time everything generated is saved to a variable so that you can travel back to the same area and when the server shuts down it can be saved to a file.

In other words we are using the same 20x20 map for the entire world and just replacing turfs.

The only reason I created a list like that is because I don't know any other way to specify what map they are on and what the 20x20 turfs that map contains. In other words I don't know any other way to "point" to a location.

Just imagine I'm trying to Code Zelda 1 for NES using one map let's put it that way.

I'm researching a datum to figure out what that is right now.
To tell you the truth I really can't see the use of a datum.

For instance the example for a datum is is:
1. Defining a Datum

To define a new data type, simply derive it from the root, rather than from an existing object type. The following code demonstrates the syntax by defining a Quest datum.


for(M in view(sponsor,1))
O = locate(quest_obj_type) in M
return 1
var/obj/R = new reward_obj_type(M)
M << "You have completed the quest!"
M << "[sponsor] takes [O] and rewards you with \an [R]."

As you can see, object variables and procs are defined just as with any other data object. Inheritance works the same too, so you can derive new types from ones you have already defined.


For me I would just stick those variables and procedures on the player. So I don't see the actual initial use or how it would help me point to a world location, map location and finally the turf that goes there. I hope I didn't distract too much from my initial question, but I couldn't figure out how a datum would replace a situation where I need four sets of numbers to narrow down to a specific turf location.
Best response
A datum is a unit of organization; it has lots and lots of point to it. When you spoke of "multidimensional variables", that's really closer to what you needed. They save and load beautifully, much better than lists, and will serve you far better.

Regarding the quest example, there is no excuse to put quest vars with the player. If you have a robust RPG, quests should be all over the place, and the only thing the player should have is a list of which quests they've accepted/completed and which stage each is at.
Okay, so what your saying is if I save a map like this in one of my games.

mob/verb/SaveMap(FileName as text)
var/tmp/player_sav = "maps/[FileName].sav"
var/tmp/savefile/F = new(player_sav)
var/tmp/Z = usr.z
x; y

//Save Turf then icon_state
for(x=1, x<=20, x++)
for(y=1, y<=15, y++)
Turf = locate(x,y,Z)
F << Turf.type
F << Turf.icon_state

usr << "Map [FileName] Saved."

Then all I need to do is add another two for loops above that to save the entire world if said world has a grid of maps? If so then I understand how to put it into a file but how would I put that same information into a variable without it being multidimensional or a list of lists?
Overall, I like the idea. Kind of makes me want to experiment with something like this. So let me paraphrase what I think is being conveyed.

1) Avoid multidimensional list, you can easily handle whatever you're trying to do using a list within a define type such an obj or in this case a datum
2) Saving/Loading the map as individual turfs/objects on such a scale will cause unwanted delay. Instead use a datum prototype, and you can store the turf/obj types & coordinates in the datum. and just create that type at the location when you want. This will process much faster than saving an entire turf/object.

Thank you guys for trying to point me in the right direction. I may not be getting the concepts your trying to explain, but my question in short is:

How do I refer to a particular position without using a multidimensional list because I need X as well as Y to refer to a position right?

I can pack stuff into a file in a particular order, but with a variable don't I need a different one for each turf saved?

I think my biggest challenge here is phrasing my question correctly. Trying to understand how I could pack all those turf/obj types and coordinates into a datum?

Going to experiment and read some more. Thank you everyone for your help!
I could have a different file for each map and load the file on entering I know how to do that. Though I thought I would be doing something totally wrong especially if it was multiplayer it would be doing file input and output all the time so I was trying to figure out how to save it all to one file but keep it on hand in memory somehow while server is up.
There are many ways to do it. This is probably one of the simplest ways of doing it without getting to complex.

mapobjects//datum that will store necessary information
var/otype//stores type
var/posx//coordinate x
var/posy//coordinate y
var/posz//coordinate z
New(t,px,py,pz)//Pass arguements to store
var/list/mapblock=new//initialize list that will store blocks
SaveBlock(blockname,turf1,turf2)//decide the name of the block of turfs you want to save, then pass down a turf for the bottom-left corner and turf for top right corner
mapblock[blockname]=new/list//Initializing a list within the associative list so we can group the turfs and bring the up easily
for(var/turf/t in block(turf1,turf2))
mapblock[blockname]+=new/mapobjects(t.type,turf1,turf2)//Create and add our datum objects to our list
CreateBlockSaveFile(blockname)//Save our blocklist
LoadBlock(blockname)//This will load the savefile then place the objs on map
for(var/mapobjects/dat in l)
new dat.otype(locate(dat.posx,dat.posy,dat.posz))
return l

//You should check to see if a block is already loaded, so you dont have to load from savefile and just pull from list, so you going to have to create some more functions as needed

Hopefully this is sufficient enough help.
In response to Fat Albert
Thank you Fat Albert that explains everything to the extent I needed at my level of programming! That is exactly what I needed in order to understand. You are wonderful for taking the time to post that for me I am very grateful!
Okay after staring at it for a long long time I just about understand every bit of it except for what is supposed to replace "dat".

I did learn a lot from it so far though I didn't even know you could associate a string as an index to a list on a variable instead of a number I thought it was only for savefile's! That will help a lot in the future!
keep dat as is. its just a variable abbreviated for datum. Its looping through your list of datums and recreates the block of turfs with the information stored in the datum.
It tells me dat is an undefined type though when I leave it as is.
I compiled the code myself. it had no errors.
dat will work as long as you have this defined
mapobjects//datum that will store necessary information
var/otype//stores type
var/posx//coordinate x
var/posy//coordinate y
var/posz//coordinate z
New(t,px,py,pz)//Pass arguements to store
Damn thanks Fat Albert that was my mistake on that one I altered something and it messed another piece up further in the code! Thanks for everything it has given me a great head start! :D