Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualMarkS

Posted 06 December 2012 - 09:56 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form of control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

		  if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

		  {

			   x--;

			   map[x][y] = 2;

		  }

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only increment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

		  {

			   x++;

			   map[x][y] = 2;

		  }

		  redraw();

	 }

}


#5MarkS

Posted 06 December 2012 - 09:52 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form or control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

		  if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

		  {

			   x--;

			   map[x][y] = 2;

		  }

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only increment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

		  {

			   x++;

			   map[x][y] = 2;

		  }

		  redraw();

	 }

}


#4MarkS

Posted 06 December 2012 - 09:52 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form or control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

		  if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

          {

			   x--;

			   map[x][y] = 2;

          }

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only incriment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

          {

			   x++;

			   map[x][y] = 2;

          }

		  redraw();

	 }

}


#3MarkS

Posted 06 December 2012 - 09:36 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form or control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

		  if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

			   x--;

		  map[x][y] = 2;

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only incriment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

			   x++;

		  map[x][y] = 2;

		  redraw();

	 }

}


#2MarkS

Posted 06 December 2012 - 09:35 PM

Glad I could help.

[edit]

The error you're getting is because you start "x" at 2 and deincrement it without any form or control to keep it from dropping bellow 0.

You need to do bounds checking. "x" and "y" are bounded to 0..4, inclusive.


while (game_ended != true)

{

	 if (dir == 'w')

	 {

		  map[x][y] = 0;

          if(x > 0) // Only deincrement 'x' if x > 0. If x == 0, "x--;" is skipped and the array doesn't go out of bounds.

               x--;

		  map[x][y] = 2;

		  redraw();

	 }

	 if (dir == 'e') // I'm making an assumption here to make a point....

	 {

		  map[x][y] = 0;

		  if(x < 4) // Only incriment 'x' if x < 4. If x == 4, "x++;" is skipped and the array doesn't go out of bounds.

			   x++;

		  map[x][y] = 2;

		  redraw();

	 }

}


#1MarkS

Posted 06 December 2012 - 09:25 PM

Glad I could help.

PARTNERS