I am following a tutorial for HaxeFlixel which uses the Haxe language. Now I do not have any experience in Haxe, but I decided to brave the tutorial since I do have experience in Java and Haxe as a language seems weirdly similar to Java.
So far, it was going smoothly. However, I came across this piece of code and I have several questions:
class FSM
{
public var activeState:Void->Void;
public function new(?InitState:Void->Void):Void
{
activeState = InitState;
}
public function update():Void
{
if (activeState != null)
activeState();
}
}
Now I understand that this is a class called FSM
and has a variable called activeState
.
Here are my questions:
What is the type of
activeState
? I would understand if was something likeactiveState:Void
but what does the->
accomplish? Is it used as a pointer? Is it a void pointer pointing to another void variable?What does the
?
before theInitState:Void->Void
signify?After the if statement, the
activeState
is being called like a function using the parentheses. However,activeState
is a variable and not a function. So what does the if statement do exactly?
Also another question:
public var playerPos(default, null):FlxPoint;
I understand playerPos
is an instance of the FlxPoint
class, but what does the default
and null
do?