How to align the input data in respective Columns? - winforms

I am new to C# and trying to learn it somehow. So, may be code look ugly.
Right now I'm developing a windows form application.
I am trying to create a text file where I want to save the input data from multiple Text Boxes in rows and columns.
Text file creation, data saving and data reading is working with the following code, but the data is not aligned according to the respective columns.
PadRight method and Indent changing is not working either.
kindly help me with this code to align the data accordingly.
`//Reading file through Open button in menustrip
private void OpenOCtrlOToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "All Files (*.*)|";
open.FilterIndex = 1;
open.Title = "Open file";
if (open.ShowDialog() == DialogResult.OK)
{
try
{
StreamReader read = new StreamReader(open.FileName);
string[] fileData = File.ReadAllLines(open.FileName);
var parts = fileData[4].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
ucMainPageOutline.Instance.ProjN.Text = parts[0];
ucMainPageOutline.Instance.ProjL.Text = parts[1];
ucMainPageOutline.Instance.Ownr.Text = parts[2];
ucMainPageOutline.Instance.Dsinr.Text = parts[3];
ucMainPageOutline.Instance.Sprvsr.Text = parts[4];
ucMainPageOutline.Instance.ConstT.Text = parts[5];
ucMainPageOutline.Instance.Bldr.Text = parts[6];
ucMainPageOutline.Instance.Sec.Text = parts[7];
ucMainPageOutline.Instance.MExcD.Text = parts[8];
ucMainPageOutline.Instance.ExcD.Text = parts[9];
ucMainPageOutline.Instance.ExcW.Text = parts[10];
}
catch(Exception)
{ }
try
{
StreamReader read = new StreamReader(open.FileName);
string[] fileData = File.ReadAllLines(open.FileName);
var parts = fileData[12].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
ucInputM.Instance.GWLt.Text = parts[0];
ucInputM.Instance.WallT.Text = parts[1];
ucInputM.Instance.HPSize.Text = parts[2];
ucInputM.Instance.WallL.Text = parts[3];
ucInputM.Instance.WStifness.Text = parts[4];
ucInputM.Instance.ElasticM.Text = parts[5];
ucInputM.Instance.Walldia.Text = parts[6];
ucInputM.Instance.WallK.Text = parts[7];
ucInputM.Instance.Strength.Text = parts[8];
ucInputM.Instance.Steel.Text = parts[9];
ucInputM.Instance.SprtT.Text = parts[10];
}
catch (Exception)
{ }
try
{
StreamReader read = new StreamReader(open.FileName);
string[] fileData = File.ReadAllLines(open.FileName);
var parts = fileData[18].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
ucInputM.Instance.StrutDim.Text = parts[0];
ucInputM.Instance.Strut1st.Text = parts[1];
ucInputM.Instance.StrutVS.Text = parts[2];
ucInputM.Instance.StrutHS.Text = parts[3];
ucInputM.Instance.StrutN.Text = parts[4];
ucInputM.Instance.StrutStif.Text = parts[5];
ucInputM.Instance.StrutL.Text = parts[6];
ucInputM.Instance.AnchorLoad.Text = parts[7];
ucInputM.Instance.Anchor1st.Text = parts[8];
ucInputM.Instance.AnchorAngle.Text = parts[9];
ucInputM.Instance.AnchorFL.Text = parts[10];
ucInputM.Instance.AnchorLL.Text = parts[11];
ucInputM.Instance.AnchorVS.Text = parts[12];
ucInputM.Instance.AnchorHS.Text = parts[13];
ucInputM.Instance.AnchorNo.Text = parts[14];
}
catch (Exception)
{ }
}
}
// Saving/Creating file through save button in menustrip
private void SaveSCtrlSToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog save = new SaveFileDialog();
save.Filter = "All Files (*.*)|";
save.FilterIndex = 1;
save.Title = "Save File";
if (save.ShowDialog() == DialogResult.OK)
{
string[,] P = new string[1, 11]
{
{ucMainPageOutline.Instance.ProjN.Text, ucMainPageOutline.Instance.ProjL.Text, ucMainPageOutline.Instance.Ownr.Text, ucMainPageOutline.Instance.Dsinr.Text, ucMainPageOutline.Instance.Sprvsr.Text, ucMainPageOutline.Instance.ConstT.Text, ucMainPageOutline.Instance.Bldr.Text, ucMainPageOutline.Instance.Sec.Text, ucMainPageOutline.Instance.MExcD.Text, ucMainPageOutline.Instance.ExcD.Text, ucMainPageOutline.Instance.ExcW.Text}
};
string[,] P1 = new string[1, 11]
{
{ucInputM.Instance.GWLt.Text, ucInputM.Instance.WallT.Text, ucInputM.Instance.HPSize.Text, ucInputM.Instance.WallL.Text, ucInputM.Instance.WStifness.Text, ucInputM.Instance.ElasticM.Text, ucInputM.Instance.Walldia.Text, ucInputM.Instance.WallK.Text, ucInputM.Instance.Strength.Text, ucInputM.Instance.Steel.Text, ucInputM.Instance.SprtT.Text}
};
string[,] P2 = new string[1, 15]
{
{ ucInputM.Instance.StrutDim.Text,ucInputM.Instance.Strut1st.Text, ucInputM.Instance.StrutVS.Text, ucInputM.Instance.StrutHS.Text, ucInputM.Instance.StrutN.Text, ucInputM.Instance.StrutStif.Text, ucInputM.Instance.StrutL.Text, ucInputM.Instance.AnchorLoad.Text, ucInputM.Instance.Anchor1st.Text, ucInputM.Instance.AnchorAngle.Text, ucInputM.Instance.AnchorFL.Text, ucInputM.Instance.AnchorLL.Text, ucInputM.Instance.AnchorVS.Text, ucInputM.Instance.AnchorHS.Text, ucInputM.Instance.AnchorNo.Text }
};
using (StreamWriter write = new StreamWriter(save.FileName))
{
write.WriteLine("----------------------------------------------------------------------Project Outline information---------------------------------------------------------------------------------");
write.WriteLine(" ");
write.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15} {7,-15} {8,-15} {9,-15} {10,-15}", "P.Name", "P.Location", "Owner", "Designer", "Supervisor", "C.Time", "Builder", "Section #", "M.E.Depth", "E.Depth", "E.Width");
for (int i = 0; i < 1; i++)
{
write.WriteLine(" ");
write.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15} {7,-15} {8,-15} {9,-15} {10,-15}", P[i, 0], P[i, 1], P[i, 2], P[i, 3], P[i, 4], P[i, 5], P[i, 6], P[i, 7], P[i, 8], P[i, 9], P[i, 10]);
}
write.WriteLine(" ");
write.WriteLine("----------------------------------------------------------------------Input Module Information---------------------------------------------------------------------------------");
write.WriteLine(" ");
write.WriteLine("----------------------------------------------------------------------Wall Information---------------------------------------------------------------------------------");
write.WriteLine(" ");
write.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15} {7,-15} {8,-15} {9,-15} {10,-15}", "GWL", "W.Type", "H.P.Size", "W.Length", "W.Stiffness", "W.E.Modulus", "1st.C.Dia", "K.wall", "UCS", "St.Type", "S.Type");
for (int i = 0; i < 1; i++)
{
write.WriteLine(" ");
write.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15} {7,-15} {8,-15} {9,-15} {10,-15}", P1[i, 0], P1[i, 1], P1[i, 2], P1[i, 3], P1[i, 4], P1[i, 5], P1[i, 6], P1[i, 7], P1[i, 8], P1[i, 9], P1[i, 10]);
}
write.WriteLine(" ");
write.WriteLine("----------------------------------------------------------------------Support Information---------------------------------------------------------------------------------");
write.WriteLine(" ");
write.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15} {7,-15} {8,-15} {9,-15} {10,-15} {11,-15} {12,-15} {13,-15} {14,-15}", "Strut.Sec", "Strut.1st.L", "Strut.VS", "Strut.HS", "Strut#", "Strut.Stiff", "Strut.L", "D.Load", "Anchor.1st.L", "Anchor.Angle", "Anchor.FF.L", "Anchor.S.L", "Anchor.VS", "Anchor.HS", "Anchor#");
for (int i = 0; i < 1; i++)
{
write.WriteLine(" ");
write.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15} {7,-15} {8,-15} {9,-15} {10,-15} {11,-15} {12,-15} {13,-15} {14,-15}", P2[i, 0], P[i, 1], P2[i, 2], P2[i, 3], P2[i, 4], P2[i, 5], P2[i, 6], P2[i, 7], P2[i, 8], P2[i, 9], P2[i, 10], P2[i, 11], P2[i, 12], P2[i, 13], P2[i, 14]);
}
MessageBox.Show("File Saved");
write.Dispose();
}`

This alignment problem in text file is very irritating. So, I quit saving data in text file and moved to the excel file. now I have no problem regarding alignment of the text. there are some formatting issues regarding excel but those are of minor importance.

Related

Finding Second duplicate element in an array in java

Hi Everyone, i am new to the programming world, can you please help me in finding second duplicate element in an array. i have tried but its not working.
public class FindSecondDuplicate {
public static void main(String[] args) {
int[] intArray = { 6,4,2,3,4,6,8};
int count=0;
Set<Integer> set=new LinkedHashSet<>();
for(int no:intArray)
{
if(set.add(no)==false)
{
count=count+1;
if(count==2)
{
System.out.println(no);
break;
}
}
else
{
set.add(no);
}
}
}
}
I think what you are trying to do can be accomplished using
public static void main(String[] args) {
int[] intArray = {6, 4, 2, 3, 4, 6, 8};
int count = 0;
Map<Integer, Integer> repeatCounter = new HashMap<>();
for (int i : intArray) {
if (repeatCounter.containsKey(i)) {
int repeatedNTimes = repeatCounter.get(i);
repeatCounter.put(i, repeatedNTimes + 1);
}else{
repeatCounter.put(i, 1);
}
}
for (int i : intArray) {
if (repeatCounter.get(i) == 2) {
count++;
if (count == 2) {
System.out.println(i);
break;
}
}
}
}
Find 2nd/3rd or any duplicate with Set Interface
public static void main(String[] args){
int[] array = {3, 12, 9, 3, 8, 3, 12, 4, 7, 8};
int find_duplicate = 3;
// Add all duplicates to set
Set<Integer> storeDuplicates = new LinkedHashSet<>();
for (int i = 0; i < array.length-1; i++){
for (int j = i+1; j < array.length; j++){
if (array[i] == array[j]){
storeDuplicates.add(array[i]);
}
}
}
// Traverse set for find the 2nd/3rd/any other duplicate
int count = 0;
for (int i : storeDuplicates){
count++;
if (count == find_duplicate) System.out.println(find_duplicate+" duplicate is : "+i);
}
}

i get alway an exception INDEX OUT OF RANGE at mat[i][j] = matrix[i+1][j+1]

Why am I getting index out of range in mat[i][j] = matrix[i+1][j+1]?
On the functions below I'm trying to count the determiner of a matrix.
Function eraze is to erase one line and one column so when I am filling the new matrix (array). Exception shows 'index out of range'.
func det2(matrix :[[Int]] ) -> Int {
var p : Int
p = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
return p
}
func det(matrix :[[Int]] , fo : Int ) -> Int {
var p2 : Int = 0
if (fo == 2) {
p2 = det2(matrix: matrix)
} else {
for j in 0..<fo {
p2 = matrix[j][0] * det(matrix: eraze(matrix: matrix, nb: j, dim: fo), fo: fo-1)
}
}
return p2
}
func eraze(matrix : [[Int]] , nb: Int , dim : Int) -> [[Int]] {
var mat = [[Int]]()
for i in 0..<dim-1 {
for j in 0..<dim-1 {
if (i == nb ) || (i>nb) {
mat[i][j] = matrix[i+1][j+1]
} else if (i<nb) {
mat[i][j] = matrix[i][j+1]
}
}
}
return mat
}
Your first issue is that in eraze(), you aren't initializing mat. In Swift you can't index into an empty array.
Replace:
var mat = [[Int]]()
with:
var mat = [[Int]](repeating: Array(repeating: 0, count: dim - 1), count: dim - 1)
With that change, your code no longer crashes, but it produces incorrect results.
You forgot to sum up the values of the expansion and when you do that you need to alternate the sign of the values:
func det(matrix :[[Int]] , fo : Int ) -> Int {
func sign(_ n: Int) -> Int {
return n % 2 == 0 ? 1 : -1
}
var p2 : Int = 0
if (fo == 2) {
p2 = det2(matrix: matrix)
} else {
for j in 0..<fo {
p2 += (sign(j) * matrix[j][0] * det(matrix: eraze(matrix: matrix, nb: j, dim: fo), fo: fo-1))
}
}
return p2
}
Test
det(matrix: [[1, 4, 7, 3, -6], [2, 5, 8, 4, -3], [3, 6, 10, -5, 14], [1, -2, 3, 4, 5], [6, -5, 4, -3, 2]], fo: 5)
13090
which agrees with Wolfram Alpha

Why when I Update a 2 dimensional Array it give an "Error #1010"

In my programming class,
I need to create a Tiles game with AS3 (like zelda).
On a map, the tiles are initialised black in an array and, after that, they are changing randomly each time the leftpick of a song reach a certain value.
When the tiles change, I need to update the Array with the new value. Actually, I always get an Error #1010: A term is undefined and has no properties.
This is how the tiles are initialised:
variable
private var grid: MovieClip;
private var nbRow: int = 6;
private var nbCol: int = 12;
private var oneTiles: Tiles;
private var t: Tiles;
public var tMap: Array = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
];
Creation of the map
private function createGrid(): void {
grid = new MovieClip();
addChild(grid);
for (var r: int = 0; r < nbRow; r++) {
for (var c: int = 0; c < nbCol; c++) {
t = new Tiles();
t.x = t.width * c;
t.y = t.height * r;
grid.addChild(t);
}
}
}
Set Tiles
private function displayTiles(): void {
var i: int = 0;
for (var r: int = 0; r < nbRow; r++) {
for (var c: int = 0; c < nbCol; c++) {
var t: Tiles;
t = Tiles(grid.getChildAt(i));
t.gotoAndStop(tMap[r][c]);
i++;
}
}
}
This is the function called everytime the leftpeak reach the value
private function resetTiles(): void {
for (var i: int = 0; i < grid.numChildren; i++) {
oneTiles = grid.getChildAt(i) as Tiles;
oneTiles.getTiles();
//30% chance gotoAndStop(1) black tiles
//70% chance gotoAndStop(2) white tiles
}
}
This is the source of the problem : to update the array, I added this in the for loop of resetTiles(). Whit it, I always get an Error #1010: A term is undefined and has no properties. :
private var posX: uint = 0; //global
private var posY: uint = 0; //global
tMap[posX][posY] = oneTiles.getFrame();
if(posX == 11 && posY != 5){
posX = 0;
posY++;
}else if(posX == 11 && posY == 5){
posX = 0;
posY = 0;
}else{
posX++;
}
trace(posX);
trace(posY);
}
So, where's the problem ? Normaly, with this code, each time a tile is changed, the good tile in tMap shall be updated.
I did some test, and what seems to be the source of the problem is the line tMap[posX][posY] = oneTiles.getFrame(); Still, I can't figure out why
public function getFrame():void{
this.currentFrame;
}
Let me explain how to deal with this kind of problem. As soon as you learn that a specific line gives you trouble, you need to understand the whole picture. You should learn the current state and value of each object involved, something like that:
import flash.utils.getQualifiedClassName;
function hyperTrace(prefix:String, target:*):void
{
trace("");
trace("Name:", prefix);
trace("Value:", target);
trace("Type:", typeof(target));
trace("Class:", getQualifiedClassName(target));
}
And then you start learning:
// Expected result: instance of Tiles class
hyperTrace("oneTiles", oneTiles);
// Expected result: Function
hyperTrace("oneTiles.getFrame", oneTiles.getFrame);
// Expected result: Array
hyperTrace("tMap", tMap);
// Expected result: Array
hyperTrace("tMap[" + posX + "]", tMap[posX]);
// Expected result: int
hyperTrace("tMap[" + posX + "][" + posY + "]", tMap[posX][posY]);
Then, you search for the one that does not match the expected result. Some object is not what you expected there (including values of posX and posY indices) and that is the source of the error. Now that you learned where the problem is, you should figure what exactly went wrong with your previous code or development logic so that it produced the unexpected results.
Without digging deep I'd guess that either oneTiles turned out to be undefined, or posX and posY has wrong values so tMap[posX] is undefined.

num cannot be resolved to a variable in java

I am creating program to sort the total number of hours employees work in a week in descending order. I am only having one compilation error when I try to execute my code. It says that "num" cannot be resolved to a variable...
The error occurs at following line:
sortHours(num); //Error occurs here
Where am I going wrong?
public class WorkerHours {
public static void main(String[] args) {
int[][] hours = {
{2, 4, 3, 4, 5, 8, 8},
{7, 3, 4, 3, 3, 4, 4},
{3, 3, 4, 3, 3, 2, 2},
{9, 3, 4, 7, 3, 4, 1},
{3, 5, 4, 3, 6, 3, 8},
{3, 4, 4, 6, 3, 4, 4},
{3, 7, 4, 8, 3, 8, 4},
{6, 3, 5, 9, 2, 7, 9}};
int[] weeklyHours = totalHours(hours);
sortHours(num); //Error occurs here
displayDescSort(weeklyHours);
}
public static int[] totalHours(int[][] hours){
int[] result1 = new int[8];
for (int i = 0; i < hours.length; i++){
int sum = 0;
for (int j = 0; j < hours[i].length; j++){
sum += hours[i][j];
}
result1[i] = sum;
}
return result1;
}
public static void sortHours(int[] num){
for (int i = 0; i < num.length - 1; i++){
int currentMax = num[i];
int currentMaxIndex = i;
for (int j = i + 1; j < num.length; j++){
if (currentMax < num[j]){
currentMax = num[j];
currentMaxIndex = j;
}
}
if (currentMaxIndex != i){
num[currentMaxIndex] = num[i];
num[i] = currentMax;
}
}
}
public static void displayDescSort(int[] weeklyHours){
for (int i = weeklyHours.length-1; i >= 0; i--){
System.out.println("Employee" + i + ": " + weeklyHours[i] + " hours");
}
}
}

Index out of range?

Below are two 2D objects, Array and Vector. As you can see the information described in both is identically. My game works flawlessly using the Array object, but with Vector is throws the following error:
[Fault] exception, information=RangeError: Error #1125: The index 10 is out of range 10.
var _platformMap:Array = [
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
[00, 00, 10, 10, 10, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10, 00, 00, 00, 10],
[10, 10, 10, 00, 00, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
[10, 10, 00, 00, 00, 00, 00, 10, 10, 10],
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
[00, 00, 00, 00, 00, 00, 00, 00, 00, 00]
];
var _platformMap:Vector.<Vector.<int>> = Vector.<Vector.<int>>(
[
Vector.<int>([10,10,10,10,10,10,10,10,10,10]),
Vector.<int>([00,00,10,10,10,10,10,10,10,10]),
Vector.<int>([10,10,10,10,01,01,01,10,10,10]),
Vector.<int>([10,10,10,00,10,10,10,10,01,10]),
Vector.<int>([10,10,10,00,10,10,01,01,01,00]),
Vector.<int>([10,10,10,10,01,01,01,01,01,10]),
Vector.<int>([00,00,00,00,00,10,10,10,10,10]),
Vector.<int>([00,00,00,00,00,00,00,00,00,00])
]
);
I read about that Vector objects have runtime range checking (or fixed-length checking) besides Arrays. Could this be the problem?
public class TileCollisionController
{
private var _softPlatformOpen:Boolean = true;
private var _elevatorOpen:Boolean = true;
public function TileCollisionController()
{}
public function platformCollision(gameObject:TileModel, platformMap:Vector.<Vector.<int>>, maxTileSize:uint, platform:uint):void
{
var overlapX:Number;
var overlapY:Number;
//check top-left corner
if (platformMap[gameObject.top][gameObject.left] == platform)
{
overlapX = gameObject.xPos % maxTileSize;
overlapY = gameObject.yPos % maxTileSize;
if (overlapY >= overlapX)
{
if (gameObject.vy < 0 && platformMap[gameObject.bottom][gameObject.left] != platform)
{
//Collision on top side of the object
gameObject.setY = gameObject.mapRow * maxTileSize;
gameObject.vy = 0;
}
}
else
{
//Collision on left side of the object
gameObject.setX = gameObject.mapColumn * maxTileSize;
gameObject.vx = 0;
}
}
//check top-right corner
if (platformMap[gameObject.top][gameObject.right] == platform)
{
overlapX = maxTileSize - ((gameObject.xPos + gameObject.width) % maxTileSize);
overlapY = gameObject.yPos % maxTileSize;
if (overlapY >= overlapX)
{
if (gameObject.vy < 0 && platformMap[gameObject.bottom][gameObject.right] != platform)
{
gameObject.setY = (gameObject.mapRow * maxTileSize);
gameObject.vy = 0;
}
}
else
{
//Collision on right
gameObject.setX = (gameObject.mapColumn * maxTileSize) + ((maxTileSize - gameObject.width) - 1);
gameObject.vx = 0;
}
}
//check bottom-left corner
if (platformMap[gameObject.bottom][gameObject.left] == platform)
{
overlapX = gameObject.xPos % maxTileSize;
overlapY = maxTileSize - ((gameObject.yPos + gameObject.height) % maxTileSize);
if (overlapY >= overlapX)
{
if (gameObject.vy > 0 && platformMap[gameObject.top][gameObject.left] != platform)
{
//trace("Collision on bottom");
//Collision on bottom
gameObject.setY = (gameObject.mapRow * maxTileSize) + (maxTileSize - gameObject.height);
gameObject.vy = 0;
gameObject.jumping = false;
}
}
else
{
//trace("Collision on bottom left");
//Collision on left
gameObject.setX = gameObject.mapColumn * maxTileSize;
gameObject.vx = 0;
}
}
//check bottom-right corner
if (platformMap[gameObject.bottom][gameObject.right] == platform)
{
overlapX = maxTileSize - ((gameObject.xPos + gameObject.width) % maxTileSize);
overlapY = maxTileSize - ((gameObject.yPos + gameObject.height) % maxTileSize);
if (overlapY >= overlapX)
{
if (gameObject.vy > 0 && platformMap[gameObject.top][gameObject.right] != platform)
{
//trace("Collision on bottom right");
//Collision on bottom
gameObject.setY = (gameObject.mapRow * maxTileSize) + (maxTileSize - gameObject.height);
gameObject.vy = 0;
gameObject.jumping = false;
}
}
else
{
//trace("Collision on right");
//Collision on right
gameObject.setX = (gameObject.mapColumn * maxTileSize) + ((maxTileSize - gameObject.width) - 1);
gameObject.vx = 0;
}
}
}
}
}
See example
public function platformCollision(gameObject:TileModel, platformMap:Vector.<Vector.<int>>, maxTileSize:uint, platform:uint):void
{
var overlapX:Number;
var overlapY:Number;
if(gameObject.bottom < platformMap.length && gameObject.right < platformMap[0].length)
{
//check top-left corner
//...
Example after updates
There is nothing wrong with the code you posted, but neither of those have an object at index 10? Maybe you should be looking at index 9 as it starts at 0?
Could you show how you are accessing the array/vector? I think that is where the error is coming from.
Try this code
var platformMap:Vector.<Vector.<int>> = new Vector.<Vector.<int>>(2);(
[
Vector.<int>([10,10,10,10,10,10,10,10,10,10]),
Vector.<int>([00,00,10,10,10,10,10,10,10,10]),
Vector.<int>([10,10,10,10,01,01,01,10,10,10]),
Vector.<int>([10,10,10,00,10,10,10,10,01,10]),
Vector.<int>([10,10,10,00,10,10,01,01,01,00]),
Vector.<int>([10,10,10,10,01,01,01,01,01,10]),
Vector.<int>([00,00,00,00,00,10,10,10,10,10]),
Vector.<int>([00,00,00,00,00,00,00,00,00,00])
]);
the vectors length is 10, so you can access from 0 to 9.
the vectors contain vectors, what also have a len.
try
trace("maxnumallowed", platformMap.length-1)
and note, that you can only access platformMap[n], if n is between 0 and platformMap.length-1

Resources