ID:171381
 
I don't know if this is the right forums but I've always wondered how to break a loop like this. I've added some extra stuff like isnot which is not part of the DM language.

mob/proc/Action()
if(var/mob/M isnot in oview()) // note i added an isnot so if M is not in oview, don't call anything
return
else //else if M is in oview()
// do procs here
sleep(10)
Action() //calls again after 1 second.
ZDarkGoku wrote:
I don't know if this is the right forums but I've always wondered how to break a loop like this. I've added some extra stuff like <font color=blue>isnot</font> which is not part of the DM language.

> mob/proc/Action()
> if(var/mob/M isnot in oview()) // note i added an isnot so if M is not in oview, don't call anything
> return
> else //else if M is in oview()
> // do procs here
> sleep(10)
> Action() //calls again after 1 second.
>

This one should work.
mob/proc/Action()
for(var/mob/M in view(6,M))//Is not has never worked =p
return 0
else //else if M is in oview()
// do procs here
sleep(10)
Action() //calls again after 1 second.
In response to Hanns
Hanns wrote:
> This one should work.
> mob/proc/Action()
> for(var/mob/M in view(6,M))//Is not has never worked =p
> return 0
> else //else if M is in oview()
> // do procs here
> sleep(10)
> Action() //calls again after 1 second.
>


No this won't work. You have an else without any if statment preceding it. And I don't look for a debug. I made the <font color=blue>isnot</font> tag on my own as to show like "If there is no mob/M in the oview(), then do some proc, and if there is a mob/M in oview(), do some other proc".
ZDarkGoku wrote:
> mob/proc/Action()
> if(var/mob/M isnot in oview()) // note i added an isnot so if M is not in oview, don't call anything
> return
> else //else if M is in oview()
> // do procs here
> sleep(10)
> Action() //calls again after 1 second.
>


Have you tried doing something like this?
mob/proc/Action()
if(!(locate(/mob) in oview(src))) // if not locate any mobs in src's view
return // break
else // otherwise...
// Continue with other procs here
spawn(10) // spawn off another call to proc to avoid exponentional infinite looping
src.Action()


[edit]
Just changed that one line as pointed out.
[/edit]
In response to Lazyboy
Lazyboy wrote:
if(!locate(/mob) in oview(src))


Problem: The in operator has a much much lower precedence than most, so the ! takes priority. To make this do what you really want, you need to put parentheses around it and put the ! outside.
if(!(locate(/mob) in oview(src)))

Many a developer has stubbed a toe on that one.

Lummox JR