Weird compiler error: "Unexpected ("

43 views
Skip to first unread message

Paolo Mazzon

unread,
Nov 10, 2015, 12:37:44 AM11/10/15
to Haxe
So I am learning how to use Haxe/OpenFL by making a platformer. Not like on the tutorial, an organised class-based platformer. Usually, when I hop into a new engine, I set up a system with an "Engine" class that has an array/list of all the game objects. I did that in this, and tested through the whole way, and only encountered a problem when I added the player object. I've never really used Haxe before now, only C++, Python, and Gamemaker. (I've done that system in all three.) I'm probably making some stupid error I didn't study about, but any help is appreciated.

So here is the main class:
class Main extends Sprite
{
var gameEngine:Engine;

public function new()
{
super();

// Make the engine
gameEngine = new Engine();

// Create a player
var player = new oPlayer(14, 14, gameEngine);
}
}

You can see we make a new player there, that is
class oPlayer extends GameObject
{
// The player's image is a, well, player...
var bPlayer:Bitmap;

// In the init, just get the image and add it to the openfl display
public override function objectCreate(newX:Int, newY:Int, gameEngine:Engine)
{
// Load the player's bitmap
var tempImage = Assets.getBitmapData("assets/player.png");
var bPlayer = new Bitmap(tempImage);
gameEngine.addChild(bPlayer);
}
}

The player class then inherits GameObject
class GameObject extends Sprite
{
// The class needs to start the Sprite
public function new(newX:Int, newY:Int, gameEngine:Engine)
{
super();
objectCreate(newX, newY, gameEngine);

// Add the object to the game
gameEngine.addObject(this);
}

// A kind of startup function that is called by new
public function objectCreate(newX:Int, newY:Int, gameEngine:Engine)
{
// This is really mostly done by the child object

x = newX;
y = newY;
}

// Some things that will be used by the engine
public function frameEvent(gameEngine:Engine)
{
// This function inheritly does nothing
}

// It's important to note that objects must draw themselves. This is not done for them.
public function drawEvent(gameEngine:Engine)
{
// Same with this one
}
}

Which uses Engine
class Engine extends Sprite
{
// This is the array that holds all the game objects
var gameObjects:Array<GameObject>;

// Create the class
public function new()
{
super();

// Create an empty array
gameObjects = new Array<GameObject>();

// Just for debug
trace("test");
}

// Add an object to the game
public function addObject(objectToAdd:GameObject)
{
// Insert said object at the end of the array
gameObjects.insert(gameObjects.length, objectToAdd);
}
}

I really hate dumping all this code on you guys, but let me help explaining. 
Main function happens, creates Engine, then creates the player -> which should call the GameObject's constructor. 

The full error message is
Source/Main.hx:23: characters 26-27 : Unexpected (
Source/Main.hx:23: characters 29-30 : Unexpected ,
Source/Main.hx:23: characters 29-30 : Unexpected ,

That is all the code in the project aside from the imports, so there is nothing else to post.

I appreciate any help provided.

P.S. I'm compiling to Neko.

Andy Li

unread,
Nov 10, 2015, 12:49:03 AM11/10/15
to haxe...@googlegroups.com
First thing I notice is that oPlayer is an invalid name for Haxe types. Haxe requires types to have names that start with upper cased letters.
See if changing that helps.

Best,
Andy

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Mark Knol

unread,
Nov 10, 2015, 3:16:32 AM11/10/15
to Haxe
I want to mention that some of your comments don't make sense. "Create the class" for example, should be "Create the instance of the class" if you want to write it correctly. But .. this is obvious for a constructor function (that's what constructors do; creating instances). If your function says addObject, I also expect it to add the given object, so no need to repeat that multiple times. So I would not spend time adding such comments. Unless you are writing a tutorial of course :) 

I hope your problem is solved by the uppercase class name, I couldn't spot any other errors too.

Paolo Mazzon

unread,
Nov 10, 2015, 7:31:41 PM11/10/15
to Haxe


On Monday, November 9, 2015 at 9:49:03 PM UTC-8, Andy Li wrote:
First thing I notice is that oPlayer is an invalid name for Haxe types. Haxe requires types to have names that start with upper cased letters.
See if changing that helps.

Best,
Andy
I completely forgot about that. So caught up in trying to make it look like my old C++, I forgot about basic Haxe rules.

Thanks a ton man!

Anyway, I know about the comments. I'm super OCD about them, no matter how useful they are. I originally had the problem of not enough comments, but then I went a little overboard with them...
Reply all
Reply to author
Forward
0 new messages