jinn8
jinn8

Reputation: 1

Null value in HaxeFlixel?

I'm building a simple counter, and I'm getting null value after stoping the counter.

`override public function update(elapsed:Float)
{
    super.update(elapsed);

    do
    {
        if (second == lastSecond)
        {
            today = Date.now();
            second = today.getSeconds();
        }
        if (second != lastSecond)
        {
            lastSecond = second;
            count++;
            counter++;
            counterHud.updateCounter(counter);
            trace(count);
        }
    }
    while (counterStarted == true && count < 10);
}

function clickPlay2()
{
    FlxG.switchState(new PlayCounterStop(counter:Int));
}`

The clickPlay2() is a button that sets the counter to stop.

The “counter” in PlayCounterStop class (where appears as Null) :

`public var counter:Int;`

...

 `override public function update(elapsed:Float)
{
    super.update(elapsed);
    trace("In PlayCounterStop ; counter is now :" + counter); // In PlayCounterStop ; counter is now :null
    stoper.updateStop(counter);
}`

The “counter” in Stoper class :

`public function updateStop(counter:Int)
{
    background2.drawRect(0, 19, FlxG.width, 1, FlxColor.CYAN);
    add(background2);
    textcounter2.text = Std.string(counter);
    textcounter2.x = textcounter2.width - 4;
    add(textcounter2);
}`

The counter:Int is returning Null instead of showing the last value (the value of the counter stoped).

I was hoping to have the counter stoped at the last second counted instead of a null value.

Upvotes: 0

Views: 20

Answers (0)

Related Questions