ID:1202553
 
Keywords: code, help
(See the best response by LordAndrew.)
var/mob/usr/M


I'm trying to use this to make an enemy look for the usr, or M.

BUT, whenever I use M in my code I get this error. Please help!
_________________________________________
loading Project RPG.dme
Mobs.dm:20:error: M: undefined type: M
Mobs.dm:21:error: M: undefined type: M
Mobs.dm:22:error: M: undefined type: M
Mobs.dm:23:error: M: undefined type: M
Mobs.dm:28:error: M: undefined type: M
Mobs.dm:18:warning: M: variable defined but not used

Project RPG.dmb - 5 errors, 1 warning (double-click on an error to jump to it)
_________________________________________
var/mob/usr/M is a variable named M of type /mob/usr. The error means you don't actually have a type somewhere that is /mob/usr.

Could you post the rest of the code in which that line appears in?
mob
proc
Look()
var/mob/usr/M
while(src)
if(M in oview())
walk_to(src,M,1,4)
if(M in oview(1))
step_towards(src,M)
else
step_rand(src)
break
else
for(M in view(src))
break
sleep(1)
spawn(src.mospeed)
Look()
sleep(10)
I tyink you need to put your var in the parenthesis
In response to Syama108
Best response
Right, your error is that /mob/usr isn't a valid path in your project.

There are several ways you could handle having enemies look for players: you could either loop through mobs with clients in view or by looking for a specified type players would be (such as /mob/player).

As a side note, the spawn(src.mospeed) { Look(); sleep(10); } block will never be called (nor would you want it to, because you've already set up Look() to be a loop; calling it recursively would cause your game to stack overflow.)

Linkin5622 wrote:
I tyink you need to put your var in the parenthesis

This wouldn't change much, and it's perfectly fine to declare variables before using them.
mob
proc
Look()
var/mob/player/M
while(src)
if(player in oview())
walk_to(src,player,1,4)
if(player in oview(1))
step_towards(src,player)
else
step_rand(src)
break
else
for(player in view(src))
break
sleep(1)
Still didnt work.. same thing, what should I do? :(
In response to Syama108
You're close! However, you named the variable M but you use player as an argument. You either need to rename var/mob/player/M to var/mob/player/player OR change all those times you used player as an argument to M.
mob
proc
Look()
var/mob/player/player
while(src)
if(player in oview())
walk_to(src,player,1,4)
if(player in oview(1))
step_towards(src,player)
else
step_rand(src)
break
else
for(player in view(src))
break
sleep(1)
I put var/mob/player/player but I still get the undefined type thing..
In response to Syama108
You need to actually have the type /mob/player defined in your project somewhere, and your players need to be using that type for their mobs.