ID:2353749
 
Code:
N/A still.

Problem description:
I am working on a way to save/load certain objects, my first idea was just to simply check location and info, and apply the new objects stuff when it seemed alright. But I also have objects that move and still need to be saved.


So TL;DR,
Is there any method/way to keep track of specific objects through a reboot? I was thinking of giving them all a code, but that isnt reliable I think.. unless someone knows better of course!
You could use the item's initial spawning x/y.
True, but what if the object moves? Then the original spawns as well, and you have 1 saved and 1 mapped. So that was where I hit a road block. Even pixel loc isnt reliable enough
You'd probably need to use some kind of ID system, then when an object loads you check the world for an object with that same ID and remove it.
So what if the object moves? The whole point is you can continue to reference it with, say, a list of hashes mapped to the object they point to. When you load, just check if there was already something created at that spot and if so, overwrite it.

ie
var/global/list/object_keymap = list()

/obj/New()
. = ..()
object_keymap["[x]-[y]-[type]"] = src

//Let's say this proc loads all the objects
/world/proc/LoadAllObjects()

//Let's say you have an object you've loaded called loaded
var/obj/loaded = LoadOneObject()
var/obj/dupe
if((dupe = keymap["[loaded.x]-[loaded.y]-[loaded.type]"]))
loaded.Move(dupe.loc)
qdel(dupe) //or whatever you want to do to the dupe


Obviously you'd only want to save some types of objects and not all of them or else this list would get needlessly huge.
If the object moves, then for one your hash is invalid. Because XYZ are no longer as they were. That means I can't use XYZ and Type as a hash also because there are multiple of the same objects in one place.

Secondly, if the object moves, then the original mapped-in object is still going to return on round start, thus creating one dynamic copy, and one mapped object.