ID:1882404
 
(See the best response by Rotem12.)
Save Code:
    for(var/mob/Robot/S in world)
ActiveRobots.Add(S.name)
save["[S.name]_name"] << "[S.name]"
save["[S.name]_x"] << "[S.x]"
save["[S.name]_y"] << "[S.y]"
save["[S.name]_z"] << "[S.z]"
usr << "\green The Robot List has been saved!"

The Saving proc is working just fine, posted just for reference. The list (ActiveRobots) is created with:
var/world/list/ActiveSagas = new /list


Load Code:
    var
Bot_x
Bot_y
Bot_z

for(var/CBot in ActiveRobots)
var/SPath = text2path("/mob/Robot/[CBot]")
var/mob/EBot = new SPath()

load["[CBot]_x"] >> Bot_x
load["[CBot]_z"] >> Bot_y
load["[CBot]_y"] >> Bot_z
EBot.loc = locate(Bot_x,Bot_y,Bot_z)
ActiveRobots -= CBot

usr << "\green The Sagas have been successfully Loaded!"

Problem description:
The code is supposed to Save all the Robots currently on the map, then Load them later on to the same place they were at..
But I keep getting the following error:
runtime error: Cannot create objects of type null.
proc name: Robo Load (/proc/Robo_Load)
usr: Dolev (/mob/Player)
src: null
call stack:
Robo Load()
Dolev (/mob/Player): Robo Load()


..Any help? I've been at it for hours..
Thanks in advance for anyone willing to help :)
Sounds like your variable null, therefore you're trying to create something with no type. Usually indicates text2path() is failing due to an invalid path or invalid format.
Best response
According to the runtime SPath equals null, which means text2path returns null because there's no such a path.

What I want to know is what are all the child paths of Robot.


You can simply do some text output to world to see what text it's trying to convert to a path.
    for(var/CBot in ActiveRobots)
world << "/mob/Robot/[CBot]"
var/SPath = text2path("/mob/Robot/[CBot]")
var/mob/EBot = new SPath()


It's possible that if you have under lines in the defined paths, it'll be converted to spaces when you use the name variable causing the path to be wrong.

Instead of /mob/Robot/My_Name, you'll get /mob/Robot/My Name

This is one possible error I could think of, there may however be another problem.
Finally! Thank you, now I know why this error keeps showing..
There were 2 main problems, the first one is as you thought - Underlines became spaces.
Another problem was that their names are not identical to their path-name, as they had the word "Robot" at the beggining of their names..
One solution I can use to solve the 2nd problem, is adding the word "Robot" before their name in the text2path proc.
But that still won't solve the underlines problem..

Is there any way to convert any space found in the var back to an underline? Changing their actual names will take me a long time, because there are MANY robots in the game..
Or, another thing I can do is use their Path instead of their Name, and then there will be no need to edit it in any way..
I will try applying the 2nd solution, but am still curious as for how to do the spaces-to-underlines thing.. Anyone can explain it to me? Is it done by using FindText?

Thanks again :D
I suppose you can use a simple text replace proc.

proc
replace(string, needle, new_string, start=1, end=0)
while(findtext(string,needle,start,end))
var/pos = findtext(string,needle,start,end)
string = copytext(string,1,pos) + new_string + copytext(string,pos+length(needle))
return string


It'd look something like this:
for(var/mob/Robot/S in world)
var/n = replace(S.name, " ", "_")
ActiveRobots.Add(n)
save["[n]_name"] << "[S.name]"
save["[n]_x"] << "[S.x]"
save["[n]_y"] << "[S.y]"
save["[n]_z"] << "[S.z]"


Question though, since you're basing it off type, is there only 1 robot of each type in the world?

Or you know, just using S.type instead of S.name to store the data.
Thanks, Rotem :)
And Nadrew, that's what I meant I did, but.. There's still one problem I can't seem to solve,
For some reason, the part that's supposed to relocate the Robot won't work:
EBot.loc = locate(Bot_x,Bot_y,Bot_z)

When I check the robot's location, its x, y and z equals 0.
To test it, I tried changing the robots location to the user's location instead, which did work.
Also, I tried displaying the vars to check if any of them equals 0 for whatever reason, but all the vars are right just before the teleport.. So, what can cause this problem?
The code is pretty much the same and is working perfectly, except for the part where it should relocate the mob..

Edit:
There, so it'd be easier to understand my problem:

    for(var/CBot in LoadedBots)
var/mob/EBot = new CBot()
load["[EBot.name]_x"] >> Bot_x
load["[EBot.name]_z"] >> Bot_y
load["[EBot.name]_y"] >> Bot_z
world << "\blue [EBot.name] ([Bot_x],[Bot_y],[Bot_z])" // e.g Mybot (12,127,1)
EBot.x = Bot_x
EBot.y = Bot_y
EBot.z = Bot_z
world << "\blue [EBot.name] ([EBot.x],[EBot.y],[EBot.z])" // Mybot (0,0,0)
LoadedBots -= CBot
You want to set x/y/z all at the same time, if any of those values are 0 when the others are set, they'll all become 0.

You could do something like: new CBot(locate(Bot_x, Bot_x, Bot_z))

The new instruction always takes a location as its 1st arg. (you could just do all of this in the constructor of CBot anyways)

But, because of the way you're loading things, you might have to just do EBot.loc=locate(Bot_x...), which should totally work assuming all those variables are numbers.
I can't locate him the moment I create him, because I use his name (after he's created) to load his location from a savefile.

For some reason, wheter I use locate(x,y,z) or x = x, y = y, z = z, or even use a turf's location or another variable, whenever I set the created mob's variables to those variables (x,y,z), be it all at once or one at a time, they all equals 0.

Even though when I try and display those variables' values, I get the correct values, the moment I set them they change to 0, somehow.

And if I try to set the variables to any other value, it works perfectly.. Why is that?

Edit: As I wrote above, i've already tried using
EBot.loc = locate(Bot_x,Bot_y,Bot_z)


The results are the same - Even though the variables do contain the right values, the moment I set EBot's values as those variables, they all become 0. It only happens when I try setting CBot's variables into these values, any other value works just fine.. Anyone knows why?
Are Bot_x etc strings or number values?
It saved the previous x, y and z of the mob, then it should be a numerical value .. Unless, for some reason, it was saved as string
save["[S.name]_x"]     << "[S.x]"
save["[S.name]_y"] << "[S.y]"
save["[S.name]_z"] << "[S.z]"


..I just realized I actually did set it as a string.. should've wrote S.x instead of "[S.x]".. That wasn't very bright of me.. Thanks :)
In response to Super Saiyan X
Never mind, that didn't solve it either :/
Any other ideas? Anyone? I can't seem to figure it out..
As shown below, the values are correct, but instead of relocating to the specified variables' values (Bot_x, Bot_y, Bot_z), EBot will relocate to (0,0,0).
And if I try relocating it to anywhere else (by not using these variables), it will relocate correctly.
Any clues?

Saving Proc:
    ActiveRobots = new /list

for(var/mob/Robot/S in world)
ActiveRobots.Add(S.type)
save["[S.name]_name"] << "[S.name]"
save["[S.name]_x"] << S.x
save["[S.name]_y"] << S.y
save["[S.name]_z"] << S.z
save["Robot List"] << ActiveRobots


Loading Proc:
    var
Bot_x = 1
Bot_y = 1
Bot_z = 1

var/list/LoadedRobots = new /list
load["Robots List"] >> LoadedRobots

for(var/CBot in LoadedRobots)
var/mob/EBot = new CBot()
load["[EBot.name]_x"] >> Bot_x
load["[EBot.name]_z"] >> Bot_y
load["[EBot.name]_y"] >> Bot_z
world << "\blue [EBot.name] ([Bot_x],[Bot_y],[Bot_z])" // For debugging purposes, shows the location EBot should be relocated to (e.g (MyBot (15,76,1))
EBot.loc = locate(Bot_x,Bot_y,Bot_z)
world << "\blue [EBot.name] ([EBot.x],[EBot.y],[EBot.z])" // Again, for debugging, shows the location where EBot currently is, which for some reason is always (0,0,0)
LoadedRobots -= CBot
You're never setting the 'LoadedRobots' list to anything, you're looping over an empty list.
Nah, I did define it at the beggining of the code, I only posted the relevant parts here.. The only problem occuring is the location setting to 0 when I try setting it to the values I loaded
Do you mind checking that Bot_X/Y/Z are actually numbers just to be sure, do something like this, if it returns 1, it's a number.
world << isnum(Bot_X)


With this added, please show us exactly what the outputs show or at least a part of it if there's too many.

EDIT: Do so only if your problem persists after you checked the list loading Nadrew's & Pokemonred200's pointed at.
I tried using text2num before each of the values, to make sure they consist solely on numbers.. But again, the result is the same..
As for the list, I changed its name by mistake while writing it here, the actual list is loading from "LoadedRobots"
I still want to see the outputs, they can help, it's not just about them being numbers or strings.

I also thought that if you're getting outputs it means the list isn't empty, it's quite the important intel.

I'm not home at the moment so it can take some time, but, atleast I can be sure about the list not being empty, because the mob (CBot) is created correctly..

Also, when I display the vars' values in the following way:
world << "\blue [EBot.name] ([Bot_x],[Bot_y],[Bot_z])"

The output I get for each variable is the correct value.
Either way, I will try what you suggested and will tell you about the results i'm getting.
Will the following be alright?
world << "\blue [EBot.name] ([Bot_x],[Bot_y],[Bot_z]), Bot_x = [isnum(Bot_x)],Bot_y = [isnum(Bot_y)],Bot_z = [isnum(Bot_z)]"


Edit:
Just checked the values the way I wrote above - All returned as True (1), meaning it IS a number, and yet - The moment I set the x, y and z vars of EBot to those values, it becomes 0..
Why is that happening?
What does your debug output look like, before and after setting EBot.loc? And are those map coordinates valid?
Yes, the map coordinates are valid.
The first debug output displays the correct values (The mob's previous location that was loaded, for example - 10,193,1)
The 2nd debug output displays the mob's current location, which is always 0,0,0 for some reason.. (Which is my problem, I am trying to relocate the mob to the location loaded (the one it displays in the first debug output)
Page: 1 2