ID:140643
 
Code:
proc
dobattle(mob/n,mob/m)
var/dmg=m.def-n.att
dmg<=0 ? dmg=0 : world<<dmg


Problem description:

loading BattleSys x2.dme
BattleSys x2.dm:4:error: expected ':'

BattleSys x2.dmb - 1 error, 0 warnings (double-click on an error to jump to it)


I've began to think that this isn't the correct usage for the ?: operator, or is this simply an error on my behalf?
That isn't the correct usage of the operator. Stick to using if() statements.
In response to Kuraudo
Note that what you wrote would have been essentially correct in another language. DM simply restricts where you can perform certain operations, like assignment. Even so, it would not have been a particularly valid use of the ? operator.
A0 wrote:
Code:
> proc
> dobattle(mob/n,mob/m)
> var/dmg=m.def-n.att
> dmg<=0 ? dmg=0 : world<<dmg
>
>

Problem description:

loading BattleSys x2.dme
BattleSys x2.dm:4:error: expected ':'

BattleSys x2.dmb - 1 error, 0 warnings (double-click on an error to jump to it)


I've began to think that this isn't the correct usage for the ?: operator, or is this simply an error on my behalf?


proc
dobattle(mob/n,mob/m)
var/dmg = m.def-n.att > 0 ? m.def-n.att : 0
world << "[dmg]"
In response to Nielz
Or you can use max() for that... in fact, in the honor of promoting modular programming, you should have a procedure defined for taking/adding health and other stats which can increase the efficiency of your system!

For example:
mob/proc/TakeHP(amt=0, mob/killer)   //   Called by doing X.TakeHP(amount of damage to be done [or -ve to heal], killer reference if any])

src.hp = max( min(src.hp-amt, src.maxhp), 0)
/*
max() choses the highest # and min() choses the lowest.

For min(), we have maxhp there so that the highest value hp can be is maxhp (because if hp-amt > maxhp, maxhp will be returned by min().

For max(), we have 0 so that the lowest possible hp value is 0 (max() of hp-amt < 0 will pick 0).

You kinda have wrap your head around that a few times to get what I just said >_>
*/


src.client.HealthbarUpdate() // If you have something like that, this is the best place to put it instead of the hud bars updating every second uselessly. Update it when needed!
if(src.hp <= 0)
src.Dead(killer) // Sends killer as the argument for the Death procedure...
In response to GhostAnime
Thank you Ghost, I shall integrate and learn from that which you have shown me ;o