ID:139236
 
Code:
mob
Enemy
New()
set background = 1
..()
AggroCheck()
proc
AggroCheck()
do
world << "<font color=red>Starting for loop to search mobs nearby.</font>"
for(var/mob/Player/M in oview(src.aggrorange))
world << "<font color=red>Mob [M] found!</font>"
if(M.Playerflag==1)
world << "<font color=red>Mob's Playerflag is [M.Playerflag]</font>"
src.target=M.name
world << "<font color=red>[src]'s target is [src.target]!</font>"
src.combatflag=1
src.aggroName.len++
src.aggroList.len++
src.aggroName[1]+=M.name
src.aggroList[1]+=0
world << "<font color=red>aggroName(1) = [src.aggroName[1]] - aggroList(1) - [src.aggroList[1]]</font>"
break
sleep(10)
while(src.currenthp>0&&src.combatflag==0)
verb
Set_Combat_Flag(mob/M in oview())
set category="Debug"
if(M.combatflag==1)
M.combatflag=0
M.target=null
src.Playerflag=1
else M.combatflag=1
world << "<font color=red>[M]'s combat flag is set to [M.combatflag].</font>"
if(istype(M, /mob/Enemy/))
M:AggroCheck()


Problem description:
So I'm having an issue with this little snippet of code. What's supposed to happen here, is that the mobs start looping through the mob's defined aggro range, and look for a mob with a Playerflag set to 1, indicating that it's a player mob. I know I could do this by just checking the client, but that's irrelevant.

Once the mob finds a player in range, it sets that player to their internal target var, and stops looping. The lists are just threat lists, one for the name of the player on the threat list, and the other for the threat value. All of the world statements found in this code are simple debug statements so I know what's going on.

Now, the problem I'm having, is that the mob will perform the loop, once it finds a mob, it sets the target, stops looping, adds the player's name to their threat list, and sets an amount (0). It also sets the mob's combat flag to 1, so that the loop does not start up again. Everything works like it's supposed to!...until I use the debug verb to reset the mob's flag to 0. The loop starts up, but it is unable to find a player. It just continues to loop through without finding a player in range, even when one is standing next to it.

If I need to go into detail more, or post more information, please do not hesitate to ask. Thank you in advance for any help.
I don't think it's the cause of the problem, but don't use : to refer to procs. Use . just like you do for the variables.
In response to Pyro_dragons
Because my AggroCheck() proc is set up only for the Enemy class mob, and the var M only refers to mobs in general, not a specific class of mob, I can't use the . operator, because it will give me a run time error. I could run the check to see if it's a /mob/Enemy, then set M to equal /mob/Enemy, but it just seemed like more work than needed, when this method works just as well. Unless it somehow is the cause of the problem, in which case it's not working.

Thanks though.
In response to Lanaka
You get a runtime error using . instead? What is it?
In response to Pyro_dragons
Compile time, not run time, my mistake. Regardless, the error is

M.AggroCheck: undefined proc
In response to Lanaka
That is because you have to recast M as a Enemy type. Right now, it's trying to call the proc on a general mob type, which doesn't have that proc as it belongs to the subtype.

if(istype(M, /mob/Enemy))
var/mob/Enemy/E = M
E.AggroCheck()

That should solve your issue.
In response to Pyro_dragons
I....just explained all of that in my second post. Regardless, it's not the problem I'm experiencing.
In response to Lanaka
Solved my own problem.