ID:145889
 
Code:
mob/proc/Death(mob/M)
if(M.hp <= 0)


Problem description:

The code above causes the compiler to give the error "Black Sun.dme:19:error::invalid expression" when I enter the if clause, but I have an "hp" variable defined for the base type /mob.

Something tells me it's a rather basic error, but I cannot find it. I apologize in advance for not finding it.

No need to apologize, but I have a feeling the error isn't actually located there.

Look a few lines above or below it, sometimes an if() without a statement or missing parenthese can cause the error lines being messed up.

If you can't find it, post about 5 lines above that to 5 lines below, and we'll see if we can help :D
In response to DarkCampainger
DarkCampainger wrote:
No need to apologize, but I have a feeling the error isn't actually located there.

Look a few lines above or below it, sometimes an if() without a statement or missing parenthese can cause the error lines being messed up.

If you can't find it, post about 5 lines above that to 5 lines below, and we'll see if we can help :D

Above it, I have a verb called DownSlash. The source of that is:

mob
verb
DownSlash(mob/M in oview(1)) // Slash downwards
usr.angle = "down" // Set "angle" to down
sleep(100)
if(usr.angle != M.angle)
var/damage = rand(1,100)
M.hp = M.hp - damage
usr << "You attack [M] for [damage] damage!"
M << "[usr] attacks you for [damage] damage!"
else
usr << "[M] blocks your attack!"
M << "You block [usr]!"


There is nothing below the proc. All the referenced vars exist, and DownSlash is listed under mob below the vars. When I compile the verb by itself, there is no error reported.
Do you have anything below the if() line? There needs to be something in the if() statement.
In response to Kalzar
Kalzar wrote:
Do you have anything below the if() line? There needs to be something in the if() statement.

Thank you for helping me, Kalzar, DarkCampaigner. I was missing an effect (that isn't logical anyway; what's the point of an IF clause without a THEN?).
In response to Drafonis
Oooo... A system where you attack at a particular angle and enemies can block, etc.? I've set up something like that for a game I was making. It's quite interesting.
Drafonis wrote:
Code:
mob/proc/Death(mob/M)
if(M.hp <= 0)


Indeed that is embarrassing! You made your proc totally backwards.

In any death check proc, there are two inflexible rules: 1) src must be the victim. Why? Because the victim is the mob most closely connected with the entire point of the proc: death and possible respawning. To use any other var for the victim is absolutely, unequivocally wrong. 2) If you need to know who the killer is, you need to include an argument for that, and not use usr.

You included an argument, but you mixed up the killer and the victim. No soup for you!

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Drafonis wrote:
Code:
mob/proc/Death(mob/M)
> if(M.hp <= 0)

Indeed that is embarrassing! You made your proc totally backwards.

In any death check proc, there are two inflexible rules: 1) src must be the victim. Why? Because the victim is the mob most closely connected with the entire point of the proc: death and possible respawning. To use any other var for the victim is absolutely, unequivocally wrong. 2) If you need to know who the killer is, you need to include an argument for that, and not use usr.

You included an argument, but you mixed up the killer and the victim. No soup for you!

Lummox JR

I fixed the source similar to how you suggested, but now it gives a string of error messages. The adjusted source looks like this:

mob/proc/Death(mob/M)
if(src.hp <= 0)
src.hp = 100
src.x = 0
src.y = 0
src.z = 0
src.loc = (x,y,z) // Error


And the error it gives is:

Black Sun.dm:31:error::invalid expression

I tried any option I can think of - changing loc directly, dropping parenthesis, a mix of this and dropping parenthesis, and many other methods. The Dream Maker help file offers no assistance on syntax, and I'm not sure if the syntax has changed since the printed version of the Blue Book was discontinued.
In response to Drafonis
That code won't do anything, because thier x,y, and z are their current location. If you plan on changing those to a death area or something, then nevermind, but if not, you might want to rethink it a bit. The error is there because you can't set loc that way; you need to use locate(x,y,z).

So it should be something like this:
src.loc = locate(x,y,z)