سؤال

static private function timer():Void 
{

    nTimer = nTimer;
    _root.hud.timer.text = nTimer;
    nTimer = nTimer - 0.02;
    if (nTimer == 0)
    {
        nTimer = 0;
        _root.hud.timer.text = nTimer;
    }   
}

This is the timer. Every time the player hits an enemy it updates the score and goes to this function which uses the number from the timer and updates the score.

static private function updateScore():Void 
{
    var num:Number = nScore;
    num *= 100;
    num = Math.round(num)
    num /= 100;
    nScore = nScore + nTimer;
    _root.hud.score.text = nScore;  
}

The problem is, that I don't the score to display 24.23, i want it it to display a whole number, 24.

هل كانت مفيدة؟

المحلول

Sorry but I don't undestand what you mean:

static private function timer():Void 
{

    nTimer = nTimer;
    // why write nTimer = nTimer?? Is like writing 1=1

    //_root.hud.timer.text = nTimer;
    // why write this text area two times? you can write it at the end of the function
    nTimer = nTimer - 0.02;
    if (nTimer == 0)
    {
        // nTimer = 0;
        // if we are here it means that nTimer == 0, so why to set it again as =0 ? 

        //_root.hud.timer.text = nTimer;
        // why write this text area two times? you can write it at the end of the function
    }   
    _root.hud.timer.text = nTimer;
}

now for the updateScore function, what do you need? Your script rounds the num var at two decimals but doesn't use it anymore If you want to add to the rounded value the nTimer value, you have to replace nScore = nScore + nTimer; with nScore = num + nTimer;

While if you need a rounded value to 2 decimals as last value, you have to round it AFTER adding the nTimer value.

At the end, you can rould the num with a shorter script: num = Math.round(num*100)/100;

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top