haxehaxeflixelflixel

How do I solve this error: "source/MainMenuState.hx:25: characters 7-21 : Unexpected selectedOption"


I'm fairly new to HaxeFlixel and I wanted to see selectedOption change to see if there were any mistakes. But I was met with this error: Error in title

This is the file that had the error (MainMenuState.hx):

package;

import flixel.FlxState;
import flixel.FlxG;
import flixel.*;
import flixel.text.*;
import flixel.ui.*;

class MainMenuState extends FlxState
{
    var optionsPre:Array<String> = ["New Game", "Settings", "Quit Game"];
    var options:Array<String> = ["Continue Game", "Create New Game", "Settings", "Quit Game"];
    var debugSelOpt:FlxText = FlxText.new(8, 8, 0, "Debug field", 8, false);
    var selectedOption = 0;
    override public function create()
    {
        super.create();
        
    }

    override public function update(elapsed:Float)
    {
        super.update(elapsed);
        if (FlxG.keys.justPressed.UP) {
            if selectedOption == optionsPre.length { // line with the supposed error
                selectedOption = 0;
            }
        }
        
        if (FlxG.keys.justPressed.DOWN) {
            if selectedOption == 0 {
                selectedOption = optionsPre.length;
            }
        }
    }
    debugSelOpt.text = "selectedOption value: " + selectedOption;
}

I'm quite unsure what's wrong in this script. Can someone help me here?


Solution

  • You need parentheses in your if statements.

    if (selectedOption == ... )