PDA

View Full Version : Rounding variables


Malignus
12-29-2006, 07:23 AM
So, I've decided that it would be much easier and make more sense if my new difficulty settings increased enemy stats by a fixed percentage rather than boosting them by a fixed amount, even a fixed amount pegged to the player level.

I've tried doing something like the following, but unfortunately it seems that Flash isn't rounding the results to an integer:

function adjustDifficulty () {
if (gameDifficulty=="normal") {
; }
if (gameDifficulty=="hard") {
MaxHP16 *= 1.2;
Math.round (MaxHP16);


Any thoughts on what I'm doing wrong?

medhopz
12-29-2006, 07:45 AM
i dont know why it doesnt work but you can always make a new var
like so:

function adjustDifficulty () {
if (gameDifficulty=="normal") {
; }
if (gameDifficulty=="hard") {
MaxHP16 *= 1.2;
MaxHP16Round = Math.round (MaxHP16);

Jacob
12-29-2006, 11:48 AM
You cant call Math.round on a number and expect it to change. Math.round returns a value based on the number you give it, so you have to assign that returned value to your variable.

Your code doesnt assign the results:
Math.round (MaxHP16);This code assigns the rounded results back to your variable:
MaxHP16 = Math.round (MaxHP16);

Malignus
12-29-2006, 11:59 AM
Great--thanks J.J.!

medhopz
12-29-2006, 12:06 PM
i was pretty close [=

Jacob
12-29-2006, 12:33 PM
Great--thanks J.J.!

Anytime ;)

Matt
12-29-2006, 02:15 PM
Ohhh. So that's why it wouldn't work for me before...dang