ID:143880
 
Code:
mob
var
player = 0
mob
Skeleton
name = "Skeleton"
icon = 'Skeleton.dmi'
stamina = 25
var/mob/m
New()
. = ..()
spawn()
Wander()
proc/Wander()
while(src)
var/Found = FALSE
for(/mob/m in oview(3))
step_towards(src,m)
Found = TRUE
break
if(Found != TRUE)
sleep(10)
Bump(mob/m)
if(m.player == 1)
Fight(m)
else
return

proc/Fight(mob/m)
var/damage = rand(1,5)
m.stamina -= damage
m << "[src] attacks you for [damage] damage!!"
src<<"You attack [m] for [damage] damage!!"


Problem description:

someone help me it says Monsters.dm:18:error:/mob/m:undefined type path
and i dont know how to fix it ive deifned mob/m as var/mob/m
Code:
 mob
var
player = 0
mob
Skeleton
name = "Skeleton"
icon = 'Skeleton.dmi'
stamina = 25
var/mob/m
New()
. = ..()
spawn()
Wander()
proc/Wander()
while(src)
var/Found = FALSE
for(var/mob/m in oview(3))//fixed, I think
step_towards(src,m)
Found = TRUE
break
if(Found != TRUE)
sleep(10)
Bump(mob/m)
if(m.player == 1)
Fight(m)
else
return

proc/Fight(mob/m)
var/damage = rand(1,5)
m.stamina -= damage
m << "[src] attacks you for [damage] damage!!"
> src<<"You attack [m] for [damage] damage!!"
>


that should work
In response to Zzzzoot
except you need to indent under the while.
Gebsbo wrote:
Bump(mob/m)
if(m.player == 1)
Fight(m)
else
return


Some minor notes of importance here:

  • You need to actually verify that m is a mob. It could be a turf or obj. Using mob/m just tells DM to expect it's a mob.
  • That should be if(m.player), or better yet if(m.key) or such, where you don't need the player var at all. Using if(var==1) or if(var==0) for true/false values is not a good choice, since you can just use if(var) and if(!var) which are not only shorter, but more stable.
  • The else return is redundant; the proc is already ending.

    Lummox JR
What shocks me is that Lummox managed to miss thsi one:

oview(3) is, implicitly, oview(usr,3). Usr is not safe in procs. Instead, you should use oview(src,3).

Additionally: you're going to have a whole lot of redundant code if you keep on writing each mob's AI like that. You should define a type, mob/monster. Put the New(), Wander(), Bump() and Fight() procs there. Then, Skeleton should be mob/monster/Skeleton. You'll only need to change the variable unique to skeletons, such as stamina. If you want a smarter monster, then override Wander(). If you want a monster to do more damage, then you'll need to change how mob/monster/Fight() works (using a variable belonging to the mob, such as damage).

This is called inheritance, and is the heart of object-oriented programming, something you'll need to learn if you want to make games.