ID:262235
 
mob
proc
load()
if(fexists("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn"))
var/savefile/Q = new("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn")
var/mob/m=new()
var/client/c=src.client
Q["mob"]>>m
Q["x"]>>m.x//Lawl, error'd
Q["y"]>>m.y
Q["z"]>>m.z
for(var/obj/o in world)
if(locate(o.type) in m.contents)
del(o)
m.updatehud()
c.mob=m
del(src)
return
src.loc=locate(1,1,1)
save()
if(src.x&&src.y&&src.y)
var/savefile/Q = new("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn")
Q["mob"]<<src
Q["x"]<<src.x
Q["y"]<<src.y
Q["z"]<<src.z

I get an error saying "Cannot read null.x". =/
BUT, it still loads the X, Y, Z and everything else, so I don't see what's going on. =/
There are a few problems with this code.

  • You don't need to create a new mob before loading one into m.
  • You can't load directly to the x, y, z vars of the mob, because the mob's default loc is null. Changing just one of those vars when the others are 0 will have no effect. You have to load x,y,z to local vars, and set the mob's loc from those.
  • The whole bit with looping through all var/obj/o in the world and deleting anything that matches an item in m.contents makes no sense whatsoever. I can't see any use for that code except to cause things to disappear for no reason.
  • The client's mob doesn't have to be set to m, because if m was saved with the same key var, client.mob will change to that mob as soon as it loads.

    Lummox JR
In response to Lummox JR
The only need to do that object loop is one player game, and, obviously, I don't really want to save a huge map. :p

Also, I did as you said (I think), and come accross another error. :'(

mob
proc
load()
if(fexists("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn"))
var/savefile/Q = new("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn")
var/mob/m=new()
var
sx
sy
sz
Q["mob"]>>m
Q["x"]>>sx
Q["y"]>>sy
Q["z"]>>sz
for(var/obj/o in world)
if(locate(o.type) in m.contents)//Here I am!
del(o)
m.loc=locate(sx,sy,sz)
m.updatehud()
del(src)
return
src.loc=locate(1,1,1)


It still renders the mob as null (Cannot read null.contents). :'(
Sorry for being a nub...
In response to Hell Ramen
Hell Ramen wrote:
The only need to do that object loop is one player game, and, obviously, I don't really want to save a huge map. :p

That makes no sense, since the object loop doesn't do what you apparently think it does. Truly that object loop is completely useless if not counterproductive and you should remove it until you can replace it (if need be) with something else.

Also, I did as you said (I think), and come accross another error. :'(

You didn't do what I said. Note:

  • You don't need to create a new mob before loading one into m.

    But in your code:
var/mob/m=new()


You implemented only one change of the recommended three: the use of local vars sx,sy,sz.

And seriously, whatever that obj loop is supposed to do, that's not anywhere near what it does.

It still renders the mob as null (Cannot read null.contents). :'(

Then quite likely no mob was saved under "mob" in the savefile.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Then quite likely no mob was saved under "mob" in the savefile.

Lummox JR

I fixed everything else. :o
BUT, the null.contents error still comes up, and it did do what I wanted it to do when that error didn't come up. :'(
I opened up the savefile with a savefile editor, mob was there. =/ I'm also saving it.
In response to Hell Ramen
:(
I sadly don't get this...and I want to konw why it doesn't work. x_X
In response to Hell Ramen
Hell Ramen wrote:
:(
I sadly don't get this...and I want to konw why it doesn't work. x_X

Well, I'd have to see the code in its current state to render any further input.

Lummox JR
In response to Lummox JR
mob
proc
load()
if(fexists("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn"))
var/savefile/Q = new("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn")
var
sx
sy
sz
Q["mob"]>>src
Q["x"]>>sx
Q["y"]>>sy
Q["z"]>>sz
for(var/obj/o in world)
if(locate(o.type) in src.contents)
del(o)
src.loc=locate(sx,sy,sz)
src.updatehud()
return
src.updatehud()
src.loc=locate(2,2,1)
save()
if(src.x&&src.y&&src.y)
var/savefile/Q = new("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn")
Q["mob"]<<src
Q["x"]<<src.x
Q["y"]<<src.y
Q["z"]<<src.z


=/ I think that should work, but, it really confuses me.
In response to Hell Ramen
How are you calling these? They work for me.

~X
In response to Xooxer
Xooxer wrote:
How are you calling these? They work for me.

~X

_>
Login and Logout(), I guess I should do it differently, huh?
In response to Hell Ramen
Login() and Logout() of the same type? /mob??? Oh, that's definetly wrong. You should log players into a temp mob, then load them into a player mob. The temp mob would have the load() proc in it's Login() and the player mob would have the save() in it's Logout(). An example:

world
mob = /mob/temp

mob
temp
Login()
..()
load()

proc
load()
if(fexists("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn"))
var/savefile/Q = new("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn")
var/mob/m=new()
var
sx
sy
sz
Q["mob"]>>m
Q["x"]>>sx
Q["y"]>>sy
Q["z"]>>sz
for(var/obj/o in world)
if(locate(o.type) in m.contents)//Here I am!
del(o)
m.loc=locate(sx,sy,sz)
m.updatehud()
del(src)
return
var/mob/player/m = new(locate(1,1,1))
src.client.mob = m

player
Logout()
save()
..()

proc
save()
if(src.x&&src.y&&src.z)
var/savefile/Q = new("[lowertext(copytext(src.key,1,2))]/[src.key]/[src.ckey].rmn")
Q["mob"]<<src
Q["x"]<<src.x
Q["y"]<<src.y
Q["z"]<<src.z


~X
In response to Xooxer
Ooh, thanks <font color = white>Eckz</font>. I guess you learn something new everyday. :o
In response to Hell Ramen
Yes, yes you do <font color="white">Heck Noodle</font>.

~X

[Edit] To add some relavent content here (:P), you can ditch those calls to lowertext if you used src.ckey instead of src.key when accessing the savefiles. Also, you might want to place the savefiles' directories in their own directory, such as:

if(fexists("./saves/[copytext(src.ckey,1,2)]/[src.ckey]/[src.ckey].rmn"))
var/savefile/Q = new("./saves/[copytext(src.ckey,1,2)]/[src.ckey]/[src.ckey].rmn")


This will keep the 26 directories a through z out of your development folder, cleaning things up a bit. Now that I think about it, you'd do well to first save the location of that player's file to a variable, then use that in your fexists() and savefile() procs:

var/file = "./saves/[copytext(src.ckey,1,2)]/[src.ckey]/[src.ckey].rmn"
if(fexists(file))
var/savefile/Q = new(file)


That way, you only need to call copytext() once, saving some processing time. And one more thing, you can ditch that return in the load() proc. It will never be called because the proc is terminated once you del() it's src in the line above.

And something else you probably didn't know; You can place all those sx, sy and sz variable definitions on one line by seperating them with commas (,), like so:

var/sx, sy, sz


You can also mix variable types like this, so you can define object vars, lists and normal vars in the same line:

var/X=32, obj/weapon/axe=new(locate(x,y,z)), list/items=new


Nifty, no?
In response to Hell Ramen
Oy. The incomprehensible obj loop is still there. If nothing else you should 86 that completely and start from scratch with whatever you were trying to do with it.

Also, you're now loading the mob directly to src, which is generally a really really bad idea.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Oy. The incomprehensible obj loop is still there. If nothing else you should 86 that completely and start from scratch with whatever you were trying to do with it.

Also, you're now loading the mob directly to src, which is generally a really really bad idea.

Lummox JR

The obj loop works perfectly to how I want it to. :p Maybe when (if) I release this game, you'll see. :p Even though I doubt it will, just stacking it up in my Unfinished Projects folder.

Also, thanks again <font color = white>Eckz</font>!
You keep on teaching me stuff I didn't know :o