Store (int, int, int) in an array?

45 views
Skip to first unread message

Yusuf Fahry

unread,
May 4, 2016, 7:55:00 PM5/4/16
to Haxe
Hello everyone,

In HaXe, it's var array = [value, value, value]; to declare an array, right?

What if the value is something like this (RGBA) - value = (0, 0, 0, 100)?

Everytime I try, like var array = [(0, 0, 0, 100), (255, 0, 0, 100), (255, 255, 0, 100), (255, 255, 255, 100)];, it's always returned error "Unexpected ,".

Is that even possible in HaXe? Because in Python that's possible.

If can can not, what's your suggestion?

Thank you

Tarwin Stroh-Spijer

unread,
May 4, 2016, 8:26:19 PM5/4/16
to haxe...@googlegroups.com
I think you're trying to use Tuples here which Haxe does not support. You may be able to use Abstracts though I think? So you can define something like:

var array = [{r:0, g:0, b:0, a:100}, {r:255, g:0, b:0, a:50}];

The Abstract is kind of like Structs in a way? Sorry, I'm a little fuzzy on this but I hope it points in the right direction.



Tarwin Stroh-Spijer
_______________________

phone: +1 650 842 0920

Developer at Fanplayr Inc. (Palo Alto)
Original at Touch My Pixel (touchmypixel.com)
_______________________

--
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.

Justin L Mills

unread,
May 4, 2016, 8:30:29 PM5/4/16
to haxe...@googlegroups.com
You should be able to do

var arr = [[0, 0, 0, 100], [255, 0, 0, 100], [255, 255, 0, 100]];


you might want to create a typedef or class instead.

typdef RGBA = { r: Int, g: Int, b: Int, a: Int };

var arr = new Array<RGBA>();
arr.push( { r: 0, g: 0, b: 0, a: 100 } );

Also take a look at enums there is a color example and abstracts for instance based on Int.

JLM

unread,
May 4, 2016, 8:38:42 PM5/4/16
to Haxe

Yusuf Fahry

unread,
May 4, 2016, 8:54:52 PM5/4/16
to Haxe
Thank you JLM & Tarwin, I understand it now.
Reply all
Reply to author
Forward
0 new messages