Hello world not compiling



  • So I followed through, and I've successfully installed haxeFlixel on my windows 10 machine. I used notepad++ to edit the Playstate.hx file as instructed, but it throws an error that there is unexpected text.

    Specifically, it says unexpected characters on line 10 -- which is where the text variable that was created earlier. I've tried simply copy pasting the example in, but unfortunately it doesn't seem to matter--for whatever reason, it's not recognizing that 'text' is a variable.

    Here's the code:

    class PlayState extends FlxState
    {
    override public function create():Void
    {
    super.create(
    var text = new flixel.text.FlxText(0, 0, 0, "Hello World", 64);
    text.screenCenter();
    add(text);
    );
    }

    and the error

    HelloWorld>lime test html5
    source/PlayState.hx:11: characters 0-4 : Unexpected text

    Consider I've literally just copy and pasted, and I had no errors while running all the installs earlier, I'm really not sure what the problem is.

    Thanks for your help!



  • perhaps you forgot to import the Flxtext.

    package;
    import flixel.FlxState;
    import flixel.text.FlxText;
    import flixel.util.FlxColor;
    
    class PlayState extends FlxState
    {
    	var text:FlxText;
    	
    	 override public function create():Void
    	{
    		super.create();
    		text = new FlxText(0, 0, 0, "Hello World", 64);
    		text.screenCenter();
    		text.scrollFactor.set();
    		add(text);
    	}
    	
    	override public function update(elapsed:Float):Void
    	{
    		super.update(elapsed);
    	}
    }


  • @felgs said in Hello world not compiling:

    super.create(
    var text = new flixel.text.FlxText(0, 0, 0, "Hello World", 64);
    text.screenCenter();
    add(text);
    );

    the problem is that you have a misplaced ). It should be:

    super.create();
    var text = new flixel.text.FlxText(0, 0, 0, "Hello World", 64);
    text.screenCenter();
    add(text);
    


  • @felgs, notice part of the code flixel.text.FlxText that you copied from that lesson. If you are using flash develop then you can replace that code with FlxText. in that IDE, mouse click FlxText, press CTRL SHIFT 1 and the import will be created. Then the word FlxText is all you need to create text. so always use the shortcut, for example FlxColor click it. do CTRL SHIFT 1 and your finished. no need to remember all the imported stuff. if you are not using that IDE then copy import flixel.text.FlxText; and paste below the top line that has the word package; then in a function just use new FlxText



  • Thanks everyone for the responses! The main culprit was indeed not importing the flxText. This is pretty amusing, since the current Hello World tutorial on haxeFlixel says nothing about importing it to make this file work.

    However, I'm still not able to get the code compile, though for a different reason now. This hello world guide for just testing it with the command line is the one that I'm following.

    My new error, after much fussing and trying to figure out if maybe I missed something else, is twofold.

    • it has no idea what to do with text.screenCenter(); -- it throws an error every time about unexpected text.
    • If I get rid of that, I also get the fun error "unexpected add" when I try to compile it :)

    At this point, I'm really debating if this is at all worth all the effort; I'm just trying to compile the Hello World that's on the site, and it seems to be missing several bits of information I would need.

    Here's everything I have written; as mentioned before, I'm just editing it in Notepad++ for now until I'm sure I actually want to work with the language.

    package;
    import flixel.FlxState;
    import flixel.text.FlxText;
    
    class PlayState extends FlxState
    {
    
        var text:FlxText;
    	
        override public function create():Void
        {
    	super.create(
    	text = new FlxText(0, 0, 0, "Hello World", 64);
    	text.screenCenter();
    	add(text);
        }
    
        override public function update(elapsed:Float):Void
        {
    	super.update(elapsed);
        }
    }
    

    Thank you again to everyone offering solutions and help! If there's something I'm missing, please explain why and what it does if you can; I also think this stuff should probably be updated in the hello world on the actual site, because, again, there is nothing about importing the text libraries, and if you take the code as written in the tutorial, it simply doesn't work.



  • @felgs said in Hello world not compiling:

    you need super.create(); not super.create(



  • flash develop is a nice IDE. http://www.flashdevelop.org/ you can learn the API much faster with it. for example, typing text. will then display a popup box with all the functions and variables syntax to use for text. that popup will happen after you type ., such as this. or text.

    also, this is a good tutorial http://x01010111.com/haxeflixel.php



  • That did it! Thank you so much for your help, and the suggestion about an IDE. I feel like an idiot missing that little detail.



  • I am glad i could help.

    here is something to remember. I am not sure if this applies to the newer version of haxeflixel, a class name such as Reg will not give an error but will not give the correct result either when written RegReg.variable. so be careful with that. took me weeks to find that bug. :)


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.