2d array trouble

Post: #1
ok. I'm having a lot of trouble getting my 2d array to work.
here's my array code:
int badwordarray[3][5] = {
{-1,-1,-1,-1,-1}, //need a clear line between all real badwordarray
{1,2,9,8,-1}};  //map,type,x,y,dir};
This is used in my tile based game to store enemies... but it is not working very well.
My first problem was that accessing the last one in an array (badwordarray[1][5]), and multiplying it by -1 would effectively multiply the first in the next row (badwordarray[2][1]) by -1 as well. This is bad because the first in the array is supposed to be a map number, and so far, I am not using negative numbers for map numbers. I fixed this first problem by inserting the useless line of -1s.

My latest problem is that when trying to access the last integer, badwordarray[3][5], it returns a -4. As that is speed, now my enemies are moving 3 extra tiles, and completely missing all the walls inbetween.

If anyone has some time, help with either of my problems would be appreciated. I am new to Cocoa/Objective-C, so it is probably something simple I overlooked. I could post my whole code if necessary, but I bet it is just a generic array issue.

Thanks -Saxplayer13 Grin
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
int array[5]; means there are 5 positions, numbered 0..4
Quote this message in a reply
Post: #3
Darn. I knew that too.
Thanks for your quick reply. Grin

"Now I can focus on my crippling emotional pain. Oh Daddy, why won't you hug me?" ~Moe from the Simpsons
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  memcpy(stuct array pointer struct array point) unknown 22 18,977 Sep 29, 2005 03:16 PM
Last Post: unknown
  Newbie array trouble that sound again 6 5,095 Mar 26, 2005 04:25 AM
Last Post: that sound again