ID:1394244
 
(See the best response by Albro1.)
Code:
mob
var
mob/Target
meister = ""
Login()
if(src.client)
if(!src) return
var/Load = input("Would You Like to Load?","Load Game") in list("Yes", "No")
if(Load=="Yes")
var/savefile/F = new("Save/[src.ckey]")
Read(F)
F["name"] >> src.name
var/mob/M = new(usr.loc)
M.dir = usr.dir
step(M,M.dir)
if(src.name!="")
M.meister = src.name
M.Wander()
proc
Wander()
while(src)
if(src.client)
break
else
sleep(5)
for(var/mob/M in oview(10))
if(M.client)
if(src.meister==M.name)
src.Target = M
break
if(src.Target)
step_towards(src,src.Target)


to be honest, im not sure whats exactly wrong with the code, there is another section of code that has another, more specific type of NPC that uses the Wander proc and runs just fine.

you guys usually don't steer me wrong, so don't start now

...please


You don't have M defined anywhere.

Also, don't directly call Read(). You can just load the savefile to the mob:
F >> src


That calls Read() automagically.

You didn't give any errors, so I can't help you further than that.
*faceplams* mustve forgot to put the defining M part when i copied the code over, my bad, fixed the orginal post to compensate, I'll try using the F >> src

EDIT: ok, so i did that, and have been modifying the code pretty normally, and now it seems like the code is acting worse, the Load function won't load anymore.

it pulls up the next variable after F >> src that is under 'src'(like src.name for example) and says:
runtime error: Cannot read null.name
proc name: Login (/mob/Login)
usr: Bloody (/mob)
src: null
call stack:
Login()

ill try remodding due to an idea i had, but otherwise, this is causing more problems then i thought
When saving, you can use src << F to load everything into the mob, which is the equivalent to calling Write().

You can remove variables that you don't want to save by either declaring them as tmp (Which is what you should do) or removing them from savefile.dir by using F.dir.Remove() (This is better used for things like overlays and underlays, which don't need to be saved).
I'm not sure why, but you don't have an src in your Login(). You're also using usr on several occasions, and I don't know why.
well, i simplified the save/load system, and debugged the living crap out of it(even by making the part that calls for making the npc be in a proc) and the problem still seems to be relevant that the npc i make when i login doesn't follow me.
In response to Bloody m
Mind posting your updated code?
Code:
mob
var
meister = ""
verb
Save()
var/savefile/F = new("Save/[src.ckey]")
F << src
src << "You saved the game!"
Login(mob/Player)
if(src.client)
if(!src) return
var/Load = input("Would You Like to Load?","Load Game") in list("Yes", "No")
if(Load=="Yes")
var/savefile/F = new("Save/[src.ckey]")
Read(F)
src.Move(locate(1,1,1))
src.Weapon()
proc
Weapon()
var/mob/M = new(usr.loc)
M.dir = usr.dir
if(usr.name!="")
M.meister = usr.name
M.Wander()
Wander()
while(src)
if(src.client)
break
else
sleep(5)
for(var/mob/M in oview(10))
if(M.client)
if(src.meister==M.name)
src.Target = M
break
if(src.Target)
step_towards(src,src.Target)


this is the whole of the code above as it is now
Best response
1. Don't use usr in procs. This has a few exceptions, but just accept that you shouldn't do it 99% of the time.

2. Why don't you just use locate() instead of looping through oview(10)? If you set the player's tag variable to the other mob's name, you can just do this:
src.Target = locate(src.name)

i understand, Login just wouldn't cooperate with the mob creation inside it, and seems to work fine with the proc being called instead.

I tried using the tag thing, and it works perfectly.

thanks alot, this has been bugging me major for the last week
In response to Bloody m
Just to elaborate on your issue, it is because you were using oview(), which doesn't search the tile you're on. You created the mob on the tile the player is on.