• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

2 dimensional vector how do i do it? plse help

Guest
Jan 15, 2012 Jan 15, 2012

Copy link to clipboard

Copied

Ls,

Im trying to create an x/y grid in  a 2 dimensional vector for reference of a boolean flag.

I thought it would be something like this below (doesnt work😞

var tabley:Vector.<Vector.<Boolean>>;
var tablex:Vector.<Boolean>;

var y:int = 0;
var x:int = 0;
tabley  = new Vector.<Vector.<Boolean>>(mapHeight,true);
for (y = 0; y< mapHeight;y++)
{
tablex = new Vector.<Boolean>(mapWidth,true);
for (x = 0; x< mapWidth;x++)
{
  traverstablex = true;
  trace("newt:", y, x, tablex );
}
tabley = Vector(tablex);
}

it all ends after the first x loop in a miserable:

...

newt: 0 29 true

newt: 0 30 true

newt: 0 31 true

TypeError: Error #1034: Type Coercion failed: cannot convert __AS3__.vec::Vector.<Boolean>@2a380b51 to __AS3__.vec.Vector.

at FruitGamev6_fla::MainTimeline/frame2()

at flash.display::MovieClip/gotoAndPlay()

at FruitGamev6_fla::MainTimeline/testlevel()

Any help is greatly appreciated.

Regards,

Mac

TOPICS
ActionScript

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2012 Jan 15, 2012

Copy link to clipboard

Copied

a vector in flash is a "typed" array.  it is not related to a mathematical vector.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 15, 2012 Jan 15, 2012

Copy link to clipboard

Copied

Dude! im well Kglad to hear from you.

I dont understand your reply.

All i want is a vector (or an array; but since vector is so much faster.. )

That can contain:

Yrow(0) -> Xrows(10)  // xrow(0) = true,xrow(1) = true, xrow(2) = false...

Yrow(1) -> Xrows(10) // ...

Yrow(2) -> Xrows(10)

so i can reference the y,x coord and retrieve a boolena value or an int.

Some guy on a website suggested this (But cant seem to get it to work):


var v2:Vector.> ;
var v3:Vector.;

  v2 = new Vector.>();
  for (var ii:int = 0; ii < 10; ii++) {
   v3 = new Vector.();
   for (var iii:int = 0; iii < 10; iii++){
    v3[iii] = iii;
   }
  v2[ii]=v3;
  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2012 Jan 15, 2012

Copy link to clipboard

Copied

you have to datatype your vector array.  what datatype will your vector array contain?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 16, 2012 Jan 16, 2012

Copy link to clipboard

Copied

this worked for me

you didn't explain what traverstablex was so i assumed you meant tablex

tabley = new Vector.<Vector.<Boolean>>(mapHeight, true);

            for (var y:int = 0; y < mapHeight; y++)

            {

                var tablex:Vector.<Boolean> = new Vector.<Boolean>(mapWidth, true);

                for (var x:int = 0; x < mapWidth; x++)

                {

                    tablex = true;

                    trace("newt: ", y, x, tablex);

                }

                tabley = tablex;

            }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 18, 2012 Jan 18, 2012

Copy link to clipboard

Copied

Hello _spoboyle,

Thank you for your reply.

I was so busy I missed it.

Your assumption is right, that was supposed to be tablex.

Actually, apart from the Vector cast at the end, i dont see the difference. Was that it?

I was gonna use it to remove a multiplication to calculate a tile coord from the updateframe event.

I dont know if a multidim. vector retains its speed benefit.

And, because it didnt get it to work, i'm now using a singledim vector for the ycoord alone.

The x coord only requires an add. so now its:  tabley[ycoord] + xcoord.

Wich saves me serveral multiplications.

Thank you for your help.

Ill try and see if i can get some more fps using the full vector routine you suggested.

Highest regards,

Mac

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

LATEST

firstly becase the contents of tablex are typed to Vector.<Boolean> you don't need to cast (this would be different if you were using Arrays for example)

the reason the cast failed was becase tabley is typed to only contain Vector.<Boolean> and by casting tablex to a Vector it fails

Vector is not the same as Vector.<Boolean>

I have not tried it but I assume you could use

tabley = Vector.<Boolean>(tablex); //although this is totally unnecessary

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines