ID:2422922
 
(See the best response by Marekssj3.)
Code:


Problem description: my game keeps crashing when the mobs want to attack im assuming. I followed falacy's enemy ai tutorial and came across this problem
the DM says 0 errors so I have no clue whats so ever


I don't know how to fix it ive googled it as well but to no avail


if someone could help me id be so appreciated


Show us code.
like the entire thing? if so how do I send the entire thing on here?
NO, just piece where is enemy ai.
Also you can check his demo here: http://www.byond.com/games/Falacy/RPGStarter
mob/enemies
Red_Guy
icon='EnemyRed.dmi'
icon_state="EnemyRed"
Level=1
Exp=5
MaxHP=100
Str=10
Def=5
Green_Guy
icon='EnemyRed.dmi'
icon_state="EnemyGreen"
Level=2
Exp=10
MaxHP=150
Str=11
Def=6

mob/enemies/New()
src.HP=src.MaxHP
spawn(-1) src.CombatAI()
return ..()

mob/enemies/proc/CombatAI()
while(src)
for(var/mob/player/M in oview())
if(get_dist(src,M)<=1)
src.dir=get_dir(src,M)
src.Attack()
else
step_to(src,M)
break
sleep(rand(4,8))


this is all the code where the enemy ai is if u need code in different areas just tell me lol

ill check the demo but my problem is I followed his code...I have re copied (deleting and re typing it all) it in hopes of fixing it and failed so im not sure whats wrong
When you pasting code, use code tags:
<dm>
code here
</dm>

Hmm it seems to look all right to me. Maybe attack verb crash the game.
It seems to me like you lost some space, and one of the loops freeze game.


When i have a bugs/ glithes and i can't find problems like you i just comment part of code and usualy send message to output.
e.g
world<<"attack"

if code still runing i know ai code work fine, and problem is attack()

mob/proc/mainProc()
some code
//attackProc() Comment it.
world<<"attackProc"


mob/proc/attackProc()
bugged code

//if it works im sure my mainProc work properly.


Debuging is important part of coding, and we can't ask anytime what is wrong...
im having a hard time understanding what u mean...like I have lost some space?? and the problem is mostly attack but u want me to comment in between? or what??????


btw im very new to coding so im sorry that im not understanding well or at all
Best response
Oh bro, i mean space buttons.
If you have a proc like AI loop, and inside, call a attack proc. And if you not sure attack proc work properly, instead of remove code comment it.

(tab) (tab) (tab) (tab)src.Attack()
//^ this part of cod is in the enemy ai spot
//of the CombatAI() part shown above in my previous message



// Attack()
// for(var/mob/M in get_step(src,src.dir))
// var/Damage=max(0,src.Str-M.Def)
// view(M)<<"[src] hit [M] for [Damage] Damage!"
// M.TakeDamage(Damage,src)


this is the problem I commented it and the problem hasn't occurred whatever is wrong with this code is causing it (yet its exactly what fallacy put in his tutorial so im lost and very very confused)
So now we know Attack proc give a fuck, so uncoment it, and inside Attack() comment line where you take damge form mobs. And check, it? If it will work, we know problem is TakeDamage proc....
issue has been fixed thanks to marekssj3 thank you so much <3