ID:270839
 
I have been practicing coding doing various stuff and I have a problem, the mob doesent follow me. Can someone tell me what I am doing wrong and not give me code, I want to learn myself.

mob
follower
icon='m1.dmi'
Login()
usr.icon='player.dmi'
Move()
.=..()
var/oldloc = loc
var/mob/follower
if(.&&follower)
follower.Move(oldloc)
verb
Follow()
new /mob/follower(get_step(src,NORTH))
turf
icon='turffy.dmi'
1) How is "follower" defined? I mean, how do you assign it?
2) In answer to 1), it's kinda hard for you to define the follower as the variable is under Move(), which there will be no way for you to access it directly. I recommand moving var/mob/follower to the parent type, or the parent of the heiarchy (sp?) it falls under. In addition, may I suggest you modify the New() proc [note the cap'd N] to help you with assigning the follower.

mob/verb/Something() new/mob/k/kk(src)//you'll see under the path's New() proc
mob/k
var/mob/follower//everything under mob/k has this variable, which is accessable directly, unlike in Move()
kk
New(mob/M)//read up on New()
if(!M)del src//safety check
src.follower=M
src.loc=get_step(M,M.dir)


- GhostAnime - Got Questions?
In response to GhostAnime
Okay, Il try it out. Thanks.
In response to Xx Dark Wizard xX
mob
var/mob/follower
follower
icon='m1.dmi'
New(mob/M)
if(!M)del src
src.follower=M
src.loc=get_step(M,M.dir)
Login()
usr.icon='player.dmi'
usr.loc= locate(1,1,1)
Move()
.=..()
var/oldloc = loc
var/mob/follower
if(.&&follower)
follower.Move(oldloc)
verb
Follow()
new /mob/follower(src)
turf
icon='turffy.dmi'

still doesent work
In response to Xx Dark Wizard xX
I sense a double variable error


And I see what you are trying to do with oldloc... and I'll say that this is probably a waste of your time when you could use walk_to() or walk_towards() (Read 'em up). I would use walk_to() with the min. dist being 1, because walk_to() unlike walk_towards() [according to the Ref.] takes obsticles into consideration


- GhostAnime
In response to GhostAnime
I know what they do they do not follow directly. They dont follow like in an rpg party system.
In response to Xx Dark Wizard xX
A few problems I've noticed here.

1.) Your design is out of whack. You don't supply the followed to the follower and then call it the follower of the follower. Using that little piece of common sense, your New() should simply go under as mob/New().

2.) You never called the parent New() proc. Am I the only one who's against that? -_-

3.) How do you KNOW that the M supplied to that New() will be a mob at all? Hell, for all you know it could be a monkey, or a gorilla, or some other aggressive animal that you'd prefer to NOT follow you. istype'd.

In response to Xx Dark Wizard xX
Xx Dark Wizard xX wrote:
I know what they do they do not follow directly. They dont follow like in an rpg party system.

You mean like snake?

[edit]
OK, after examining your old code. I have found that I have gone crazy because of it *crys*.

/*
Right... Lets start with what I think is your beginning GUI.
*/

mob
/*
because of this variable all object instances with a mob type
will have a "/mob" type with a "follower" variable name.
Which is probably not what you want, is it?
I would think you would want a "/mob/follower" type, for I see you are declaring a mob/follower type in your definition.
Example ("var/mob/follower/F")
*/

var/mob/follower
verb
/*
Now we come to a verb which I assume is to be used by the person who wants to do the following.
Is that correct?
*/

Follow()
/* In any case if you want to keep track for future reference.
For example, in the Move() proc you call later when you move.
Then you must assign the new mob you are making to a variable.
Preferably one with the same type. Like the one you have
above declared in the mob definition.
So, "F = new /mob/follower(src)"
*/

new /mob/follower(src)
/*
Now we come to the follower types definition.
*Notice the order I go in*
*/

follower
icon='m1.dmi'
/*
Now mob/M is going to equal src of the Follow() verb.
So who ever called the Follow verb will be M.
*/

New(mob/M)
/*
This little check is ok, I guess *shrugs*, ahh assurance :P
yea if the person calling the verb was some how deleted after the follower's new proc was called.
This would simply delete the follower or src.
Which would prevent Runtime errors of "null.*" * being a wildcard of course.
*/

if(!M)del src
/*
This of course sets the follower variable of the follower type to the mob that called the follow verb.
*follower should be F*
*/

src.follower=M
src.loc=get_step(M,M.dir)
Move()
/*
Calling this runs the parent proc.
Thus oldloc will equal the src's new location.
So you should change those around.
*/

.=..()
var/oldloc = loc
/*
This is not really needed cause your declaring a local variable
which is never being initialized. Thus the bellow if statement will never be true.
*/

var/mob/follower
// Since we have a local F variable we would use that instead.
if(.&&follower)
/*
Now you should change this to F. Thus the follower's Move proc is called to move to the oldloc.
However, this causes an infinite loop.
Because if you remember correctly, in follower/New() we assigned F = M or the src or the caller of the follow verb.
This produced a cross reference. For example, src moves which calls the follower's Move().
Since follower hasn't an overload of Move() its parrent proc is called by default.
Then follower's Move calls the followers Move or F.Move() which is the src's Move().
That process repeats until a crash occurs.
*/

follower.Move(oldloc)


RIGHT, as to getting some one to follow you. That is up to you.