//For some reason this freezes when called
mob/proc/attacktest(mob/M)
var/mob/A = src
if(!M.key)
npcattacks
M.dir = get_dir(M,src)
if(src in get_step(M,M.dir))
spawn(M.attackdelay)
goto npcattacks
if(src in oview(3,M))
walk_towards(M,src)
goto npcattacks
ID:147890
![]() Oct 12 2003, 9:38 am
|
|
![]() Oct 12 2003, 1:03 pm
|
|
whats the point of var/mob/A
|
Xallius wrote:
//For some reason this freezes when called When it gets to the line "goto npcattacks" it goes back to npcattacks and will end up executing the same code again, getting to "goto npcattacks" and doing it all over again. I don't use the goto commands in byond myself, they are very rarely needed and I have not come accross a situation where I had to have them. In fact, most people that do use it are doing so when not needed and usually innapropriately. I am going to assume that you want M to walk towards the source when farther than 1 tile away and stand there attacking while next to the source. I would suggest you call the function with M as the src and pass in the thing to be walked to/attacked as the M. I will show you how to achieve what you want doing it this way anyway though, as it would apply to the changed function as well. > mob/proc/attacktest(mob/M) |
//This is the coding you sent me, properly indented, wiped
//of the comments, and with a test reply >> world. mob/proc/attacktest(mob/M) if(!M.key) while(src) M.dir = get_dir(M,src) if(src in get_step(M,M.dir)) world << "[M] attacks [src]" else if(src in oview(3,M)) walk_towards(M,src) sleep(M.attackdelay) //Unfortunately, I am still recieving the following error //when this proc is called: //Infinite loop suspected--switching proc to background. If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0. |
Xallius wrote:
//This is the coding you sent me, properly indented, wiped No, that is not properly indented. You have everything after the while and before the sleep indented one-line too few. The way I had it was correctly indented, if it did not appear so to you then it must show differently on your browser. Change that like so: > mob/proc/attacktest(mob/M) I would also suggest that you use step_towards instead of walk_towards since this is a loop and it will keep executing that line. |
//I copied that coding and replaced walk with step...
mob/proc/attacktest(mob/M) if(!M.key) while(src) M.dir = get_dir(M,src) if(src in get_step(M,M.dir)) world << "[M] attacks [src]" else if(src in oview(3,M)) step_towards(M,src) sleep(M.attackdelay) //now it freezes... //could you please test it so I know that the problem is isolated? |
The previous example of fixing the indentation didn't go far enough; the sleep() needs to be inside your while() loop.
Lummox JR |