How to call the member of this data structure type?

25 views
Skip to first unread message

Moshe Adriano Yosef Feit

unread,
Apr 24, 2016, 5:53:33 AM4/24/16
to HaxeFlixel
Hi,

This might be a noob-ish question, but I didn't find it in here.

Suppose I create an array with the following syntax:

var point:Array<{x: Float, y: Float}> = [ {x: 50.5, y: 75.5}, {x: 100.5, y: 125.5} ];

I tried calling with point[0].x and returned error! XD

Saying:

[Fault] exception, information=TypeError: Error #1010: A term is undefined and has no properties.

How to call the value of x of the first element (value 50.5) ?

Thanks

Dlean Jeans

unread,
Apr 24, 2016, 11:40:00 AM4/24/16
to HaxeFlixel
I'm not sure why but I think it's something in your code. Try to find a typo or something.


Consider
typedef Point = {
var x:Float;
var y:Float;
}

var points:Array<Point> = [ {x:50.5, y:75.5}, {x:100.5, y:125.5}];
trace(points[0].x);


Also why use this when HaxeFlixel has FlxPoint

Moshe Adriano Yosef Feit

unread,
Apr 25, 2016, 12:44:32 AM4/25/16
to HaxeFlixel
I don't why this happened, and this still  baffles me. No typos, no incomplete syntax, all good. Maybe this a library problem?



Also why use this when HaxeFlixel has FlxPoint
 
Because I need the data in 'primitive' type to be used in another methods that I think it is easier if using Haxe primitive's rather than Flixel to do the calculation.
Reply all
Reply to author
Forward
0 new messages