ID:141012
 
Code:
mob
Hollow
name = "{NPC} Hollow"
icon = 'normalhollow.dmi'
icon_state = ""
race = "Hollow"
density = 1
var/mob/target
New()
spawn() wander()
proc
wander()
for()
hasnotarget
sleep(3)
if(!target)
for(var/mob/m in oview(7, src))
if(m.race != "Hollow"&&m.NPC1 == 0)
target = m
if(!target)
walk_rand(src, 5)
sleep(3)
goto hasnotarget
sleep(2)
goto hastarget
else
hastarget
sleep(3)
if(target in oview(3, src))
var/decision = rand(1,5)
if(decision == 5)
view()<<"<b>Decision"
var/obj/K = new/obj/attacks/cero(src.loc)
K:dir = src.dir
walk(K,src.dir)
sleep(5)
walk(src, 0)
sleep(5)
goto hastarget
else
step_towards(src, target)
goto hastarget
else if(target in oview(7, src))
step_towards(src,target)
goto hastarget
else
target = null
walk(src, 0)
goto hasnotarget
Bump(mob/M)
if(M.race == src.race)
return
else
var/damage = round(src.str - M.def)
if(damage<=0)
damage = 1
flick("Attack",src)
M.health -= damage
M<<"\red <b>[src] hit you for [damage] damage! Health Remaining: [M.health]/[M.mhealth]"
M.Death(src)
sleep(7)
Bump(turf/T)
..()
Bump(area/A)
..()
obj
var
owner = null
trail = 0
obj
attacks
cero
icon = 'normalhollow.dmi'
icon_state = "tipcero"
density = 1
New()
spawn(100)
view()<<"<b>Spawned"
del(src)
view()<<"<b>Deleted"
Bump(mob/M)
view()<<"<b>Cero Bump"
if(M.NPC1 == 1)
del(src)
else
var/damage = round(usr.mrei - M.def)
if(damage <= 0)
damage = 1
M.health-=damage
M<<"[src.owner]'s [src] hit you for [damage]!"
M.Death()
del(src)
Move()
var/obj/K = new/obj/attacks/cerotrail(src.loc)
K.dir = src.dir
..()
Bump(obj/O)
view()<<"<b>Obj"
if(O.trail)
..()
else
del(src&&O)
Bump(turf/T)
view()<<"<b>Turf"
del(src)
cerotrail
icon = 'normalhollow.dmi'
icon_state = "bodycero"
density = 0
trail = 1
New()
spawn(30)
del(src)


Problem description:

Okay, I know I'm not the best or great at coding but please help me on this problem:

Whenever I'm in the game and the decision variable becomes 5, which is when its supposed to shoot a cero, it gives me a runtime error saying that it cannot modify a null direction; which I suppose means that K is null. That's where I get stuck, I'm not quite sure how K could be null or how it can't modify a null direction. Any ideas?

First a few things to keep in mind:
1) This is a non-rip game
2) I know goto is bad
3) Schnitzelnaggler helped me on the target system
4) Everything else, I coded
5) When it DID work, and the cero hit me nothing happened besides the cero was deleted as if I weren't a mob but then I tested turfs and objects as well and it seemed as if it didn't bump into anything, it just deleted itself.
6) I'm not sure if this belongs here because a few months or so ago animes were banned from the forums and I haven't been on much since then.
If you know goto is bad, why the hell are you using it?
In response to Vic Rattlehead (#1)
Because I prefer it, in any case goto isn't causing the problem and thus isn't the issue.
In response to SadoSoldier (#2)
goto is causing a problem and is an issue. Stop using it.

I'd tell you how to fix your error but you've already exhibited a complete unwillingness to improve your code so I don't see any reason to waste my time doing so.
You're(the OP, I mean) also unnecessarily using the : operator.
var/obj/K = new/obj/attacks/cero(src.loc)
//change to
var/obj/attacks/cero/K = new(src.loc)

Not that that change is even necessary, since you're using dir, which is included in /obj variables. Just change the colon to a period.
Not related to the actual problem.
While that would remove the error message it would not fix the underlying error.

Of course, Ripper man5, your suggestion that he just fake-change his code does not particularly help him at all.

I suppose I'll provide a suggestion for SadoSoldier as to how to remove the gotos (though I'm sure he already knows): because what you are attempting to make here is a finite state machine, you should do it at least semi-properly.

proc/wander()
while(src)
find a mob
if(we found a mob)
attack(thatmob)
else
step_rand()
sleep()

proc/attack(themob)
while(themob is alive and close enough to follow)
if(we're close enough to attack)
attack
else
step_towards()
sleep()


This isn't a perfect model of a finite state machine, but it's good enough for your purposes here. Notice how much better organized and easier to read it is?
Ripper man5 wrote:
Garthor, I know you want people to show there work to the best of the DM ability but just work with people on what they got. and eventually at the end tell them or prove that it is not what is necessary.

I often disagree with Gartors way of arguing with people, but I think (not that it'd matter) he is completely right here. If people want a volunteer to help, they should show a basic courtesy.


SadoSoldier wrote:
2) I know goto is bad

The problem is that the people helping you here on a volunteer base have to read through this mess, so you are basically saying you make it extra hard for them on purpose, even if you know that you are making their life harder than should be.


SadoSoldier wrote:
3) Schnitzelnaggler helped me on the target system

Whatever I may have done, I sure didn't create this.


SadoSoldier wrote:
6) I'm not sure if this belongs here because a few months or so ago animes were banned from the forums and I haven't been on much since then.

Animé has never been banned from the developers forum.
People were encouraged to post their Animé related classified ads at BYOND Animé for proper sorting and better replies. This has never inflicted any measures on forums other than Classified Ads and even there was not meant against Animé games, but to improve the replies they get (even though some people might have misunderstood the intention).