Typedef - Invalid field access

Hi,

I thought I understood how typedef works, but apparently not… :stuck_out_tongue:

I have this typedef just under my imports:

typedef Tiles_Datas = {
	var type:Int;
	var tiles:Array<Tile>;
}

Then, I have this:

class MyClass extends Sprite{
	...
	private var tiles_up_checked:Tiles_Datas;
	private var tiles_down_checked:Tiles_Datas;
	private var tiles_left_checked:Tiles_Datas;
	private var tiles_right_checked:Tiles_Datas;
	...
	
	public function new() {
		super();
		
		tiles_up_checked.type = -1;
		tiles_down_checked.type = -1;
		tiles_left_checked.type = -1;
		tiles_right_checked.type = -1;
	}
}

When I lauch the program, it gives me an error at the first line where I try to set the type at -1.

Uncaught exception - Invalid field access

How should I use Typedef? Or maybe I should create a private class just under my main class in the same file instead of Typedef?

Thank you for your help! :slight_smile:

Your variables are still null. Initialize them like this:

tiles_up_checked = {
    type: -1,
    tiles: []
};

That wasn’t hard… Thanks for the quick reply and explanation!