ID:173312
![]() Jan 21 2004, 11:20 am
|
|
sometimes in my game i want to have damage mulitplyers... the problem is that if I make it multiply damage by 1.5 then sometimes i get a decimal answer. How can I tell the game to drop the decimals off those numbers?
|
![]() Jan 21 2004, 11:37 am
|
|
round(whatever)
|
so like say this code was inside an attack thing at the end for the amount of damage done...
var/damage = 11.5 round(damage) M.HP -= damage that would round 11.5 to 12? |
Coolchris wrote:
so like say this code was inside an attack thing at the end for the amount of damage done... Not quite. Try it like this: <code>var/damage = 11.5 damage = round(damage) M.HP -= damage</code> or: <code>var/damage = round(11.5) M.HP -= damage</code> or: <code>var/damage = 11.5 M.HP -= round(damage)</code> |
I'd just like to take a moment to say thanks, Chris. You've been helpful to those trying to answer your questions, by providing actual detailed questions, and even trying out the source code for yourself without asking for the entire thing to be handed to you. We appreciate this a lot when trying to help newcomers.
So, thanks! ~Polatrite~ |
ok well i got a prob with what i was trying to use it for...
mob NPC Slime name = "Slime" icon = 'slime.dmi' HP = round(20 * (((players - 1) / 4) + 1)) Max_HP = round(20 * (((players - 1) / 4) + 1)) STR = round(40 * (((players - 1) / 4) + 1)) DEF = round(40 * (((players - 1) / 4) + 1)) SPD = round(8 * (((players - 1) / 4) + 1)) exp_give = 1 note: players is a global variable. It always gives me a message that says "expected a constant expression" how would i re-write that? |
When you're defining variables, you can only use constant values. That means you can't refer to another variable or a proc in there.
You can have this: <code>mob/var/bleh = 1</code> Or this: <code>mob/var/bleh = 1 + 9</code> But not this: <code>mob/var/bleh = 1 + src.health</code> Nor this: <code>mob/var/bleh = round(1.5)</code> If you're absolutely despirate to have non-constant values when an object is created, then use the New() proc to set the values: <code>mob/var/bleh mob/New() bleh = round(1.5)</code> |
I would like to point out that you can round up using round().
var/damage = 12.5 //1/2 of 25 This should output 13 to the world. What I did is in the reference, but here's the basics: round() takes 1 OR 2 arguments. The first one will always be the value to round. The second value is the number to round to. Using one rounds to the nearest whole number. Had you used round(12.5,0.75), you would have gotten 12.75. |
Foomer wrote:
Nor this: Actually, that line is perfectly fine. round(1.5) would always return a constant. ~>Volte |
Foomer wrote: Volte wrote: Actually, that line is perfectly fine. round(1.5) would always return a constant. That may be, but the fact that it doesn't compile causes problems. |