ID:142402
 
Just so you all know, this is just something random I decided to code, because I was bored, and need to work on my skills.

Code:

mob
verb
Kill_Everyone(mob/M as mob in world)
switch(alert("Are you sure you want to kill everyone in the world?",,"Yes","No"))
if("Yes")
var/numkilled = 0
while(M.Alive == 1)
world << "Please stand by for an important update to your character."
sleep(100)
if(M.key == usr.key) continue
else if(M.Alive == 0) continue
else
world << "Targeting... [M]"
sleep(100)
numkilled += 1
M << "HA I GOT YAH!"
world << "[M] was the [numkilled]\th killed in the world!"
del M
if(!Alive)
sleep(100)
world << "Now, the final person will die!"
world << "Targeting [usr]"
sleep(100)
usr.Die()
sleep(10)
world << "The death is finally over!"


Problem description: It works fine around compile-time, but when it initiates, I get this run-time error. Also, it does go farther than that, and the rest works fine, it's just that part.

runtime error: Cannot read null.Alive
proc name: Kill Everyone (/mob/Admin/verb/Kill_Everyone)
usr: (/mob)
src: (/mob)
call stack:
(/mob): Kill Everyone(null)

Also, no matter how long I wait, it never moves on from the while(M.Alive == 1) to killing the user, I'm really not sure why.

Procedures (proc) do not work like verbs. In verbs, the argument (within the parenthesis()) will bring an input with objects defined. This is not the case for procedures.

Thus, M in your argument is null as no argument has been passed on. You can read more of Procedures in Chapter 6 of the DM Guide

Note that alert()'s default reference (see the DM Reference entry) is usr, which you want to avoid in most procedures... not to mention that the reference is M not usr... and you are calling usr.Die() near the end, not M.Die()

In addition, you may want to read the usr unfriendly article, warning you the dangerous of abusing usr (per say). You may want to read up the Green Programming article to make your project more efficient, such as using boolean checks.
In response to GhostAnime
Oh wow, I accidentally posted that as a proc, in my code, it's a verb.

However, I meant for usr.die() to be at the end.

Also, I'll make sure to take a look at those articles you suggested, thanks.
In response to XeroXen
Ah I see... it could be a weird instance where the mob just logged out and no longer exists (actually, this can happen easily if the alert() was not "answered" quickly enough.

In any case, it is always wise to safety check:
if(!M||!ismob(M))
usr << "That person is no longer here!"
return


!M is a boolean check to see if M is a false value (0, null or empty string "") and checks if it is a /mob if M is present (in case). If M is not there or M is not a /mob, it stops the rest of the verb (aka pseudo-proc)/procedure (and returns the value of ., which is initially null).
In response to GhostAnime
GhostAnime wrote:
In any case, it is always wise to safety check:
if(!M||!ismob(M))


Doing both checks is kind of redundant; just istype()/ismob() will suffice, because even with supplied with a non-object value as the argument like null or even 0, these procs will still return 0 correctly.