ID:1388221
 
(See the best response by MisterPerson.)
Code:
if(M.HealingPower)
var/chance=30
if(prob(chance))
visible_message("\green<B>[src] is being healed by an unknown power, by [M]!</B>")
while(src.health<=99)
if(src.health>=100)
return 0 //Stops him from being healed.
if(get_dist(src,M)>=2)
M<<output("<font color=red>Your healing has been interrupted.")
src<<output("<font color=red>You feel the healing stop...")
return 0
spawn(50)
src<<output("<font color=blue><i>You feel better...")
src.health+=5//Will be changed, based on over-powerness.
else
goto yeah:
yeah:


Problem description:

Causes the game to freeze.
Best response
Long story short, replace the spawn with sleep. You're endlessly telling the program to check distance, add a command into the task queue, and then do the loop again. All without ever actually letting any time lapse.
Where's the while() loop? Show everything under the while loop so we know what's going on completely.
if("help")//Aisu Minor Power Healing.
if(M.HealingPower)
var/chance=30
if(prob(chance))
visible_message("\green<B>[src] is being healed by an unknown power, by [M]!</B>")
while(src.health<=99)
if(src.health>=100)
src<<output("<font color=red>Healing completed.")
M<<output("<font color=red>Healing completed.")
return 0 //Stops him from being healed.
if(get_dist(src,M)>=2)
M<<output("<font color=red>Your healing has been interrupted.")
src<<output("<font color=red>You feel the healing stop...")
return 0
sleep(20)
src<<output("<font color=blue><i>You feel better...")
src.health+=5//Will be changed, based on over-powerness.
else
goto yeah:
yeah:
if(health >= config.health_threshold_crit)
help_shake_act(M)
return 1
// if(M.health < -75) return 0

if((M.head && (M.head.flags & HEADCOVERSMOUTH)) || (M.wear_mask && (M.wear_mask.flags & MASKCOVERSMOUTH)))
M << "\blue <B>Remove your mask!</B>"
return 0
if((head && (head.flags & HEADCOVERSMOUTH)) || (wear_mask && (wear_mask.flags & MASKCOVERSMOUTH)))
M << "\blue <B>Remove his mask!</B>"
return 0

var/obj/effect/equip_e/human/O = new /obj/effect/equip_e/human()
O.source = M
O.target = src
O.s_loc = M.loc
O.t_loc = loc
O.place = "CPR"
requests += O
spawn(0)
O.process()
return 1


This is the whole code, I need the While loop to stop at the sleep() to go back up.
One thing unrelated to your question..
                     if(src.health>=100)
src<<output("<font color=red>Healing completed.")
M<<output("<font color=red>Healing completed.")
src.health = 100 //This will make sure they don't go over the health a little.
return 0 //Stops him from being healed.

As for making it stop.. sleep() is in the right place. When running a while loop it'll go from if(src.health...) to src.health+=5... until the while() statement is false. So that sleep function will slow down the while loop. sleep(20) = 2 seconds by the way.

Why do you need goto yeah:? Just press tab and shift all the code under "else". In my opinion, goto should only be used when you don't want to rewrite a code that is already "above" your current code. So you use goto to go back up and repeat or skip lines of code.

As for it freezing, if this whole entire code is mob/proc/process() there's a chance it would repeat itself and in turn crash you due to

spawn(0)
O.process()
<dm>

But I wouldn't know that because I can't see the top as to where this code is located.
You really shouldn't be using goto here. There are very few situations where you ever should use goto.

Just remove your else clause containing the goto, and the label entirely.
You should NEVER use goto. There are always better solutions. If you're using it as a loop, make an actual loop using for or while. If you're defining a section and then jumping to it as needed, define that section as a whole separate proc. If you're iterating by calling the same proc over again, use .()
In a non-inline language, goto can make sense to eject processing from non-terminable loops, but BYOND has the break keyword, so even that use is... Well, improper.

I don't know of any cases where goto should be used over a proper loop, or proper codeflow. I still won't say never, because there may be an obscure use for it that I don't know of.

That said, if you are using goto, odds are, you are using it in place of something that should be there, because after 15 years of programming, I have only seen goto used in certain non object oriented languages that don't have things like definable functions, etc.
Lol.

"That said, if you are using goto, odds are, you are using it in place of something that should be there, because after 15 years of programming, I have only seen goto used in certain non object oriented languages that don't have things like definable functions, etc."

In my CPU Check Loop I have a goto that makes it repeat itself every 5 seconds. The funny thing is.. I was just too lazy to put a simple while loop there that made sense since it'd probably have to be changed a few times. (while(true) wouldn't work out here). ._. So what Ter13 just said made me laugh. Because I knew what I was doing. Being lazy.