ID:138800
 
Code:
obj
zombie
icon = 'beings.dmi'
icon_state = "zombie"
var/target = ""
New()
world << "a"
..()
world << "b"
zombie
world << ":::[target]"
if(target == "")
world << "getting target"
for(var/mob/a in view())
if(!(a.ckey == ""))
target = a
goto zombie
else
var/mob/a = target
world << "c"
if(a.y < src.y)
step(src,SOUTH)
world << "c"
goto zombie
if(a.y > src.y)
step(src,NORTH)
world << "a"
goto zombie
if(a.x < src.x)
step(src,WEST)
world << "d"
goto zombie
if(a.x > src.x)
step(src,EAST)
world << "b"
goto zombie</b>


Problem description:i doubt it was that easy but this is my first ai i made it so it had a "test" it should say
a b ::: :::[mob here] c and then a,b,c or d a being north b east c south and d west but it says everything but the direction can someone please help me?

stages:
a starting targeting
b making sure ..() didnt effect something
:::[target] the target it foundshould be empty first cause it dosnt have a target
c if found a target so it goes to getting the dirrection
a,b,c,d it found a direction and started moving to it(dosnt work :/)

You are making this a lot more difficult than it needs to be.

obj
zombie
// your other stuff here
var/mob/target

New()
..()
spawn()ai() // when we are created, out mind is aswell!

proc/ai()
spawn()while(1) // start a loop, use spawn so it doesn't hold up the game

if(target && target in oview(src)) // if a target exists and is in your view

if(get_dist(src, target) > 1) // if the distance between you and the target is greater than 1
step_to(src, target) // step to the damn target cause you're mighty hungry
else
world << "nom nom nom" // the target is right in front of you, ATTACK!


else // if there is no target, or the previous target is simply too far

// best get a target, i reckon
for(var/client/c) // if the zombie's targets can be non-clients, do for(var/mob/m in oview(src)) instead
if(c.mob in oview(src)) // if the client's mob is within the zombie's view
target = c.mob
break // we have found our victim, no sense in looking for more

if(!target) // if no target found
step_rand(src) // step randomly!

sleep(10) // add a delay, which can be less than 10, to prevent inf loop
// you could probably add delays after the actions instead of just at the end
// therefore, if no target is found, the delay can be longer than when a target is in sight!
In response to XaKING
thanks :D
In response to XaKING
note: The conditional if(a && a in List) will not evaluate as expected. Instead, you should put the a in List in parentheses.

note 2: spawn() with no given argument can be written without the parentheses.