Chat on IRC |
arrays, help with
Posted by Cobbs [send private reply] at October 19, 2001, 11:43:44 PM
I'm making a tile based rpg, in java. My problem is something to do with these arrays. I've spent alot of time on this and i'm still not getting it.
Tile[][] myTiles = new Tile[20][15]; FileReader theFile = new FileReader(mapSource); for(int y = 0; y < 15; y++) for(int x = 0; x < 22; x++) //using 22 as of now, explained below... { switch(theFile.read()) { case 'g' : myTiles[x][y] = new Grass(); break; } } So what is does is read though a file that I've made with notepad. Since it's monospaced or whatever it works as a map editor. I'm going with 22 up there because here is one of the maps as an example... gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg gggggggggggggggggggg EOF (there is a new line after the last line of g's) When i ran some little program I made to look at it, for example a line went... 103 103 103 103 103 103 103 103 103 103 103 103 103 103 103 103 103 103 103 103 13 10 103 = g 13 and 10 = new line Counting normally, that's 22 values for ascii values, so my loop goes to 22 because in the array the first ones 0, making the last one go into spot 21 (good thing I cleared that up... :p) It also goes to 22 not 20 because I have to throw out those last two chars, so they don't end up as the first two on the next line. The problem I'm getting is a null pointer exception. Thanks
Posted by Cobbs [send private reply] at October 20, 2001, 01:34:55 PM
The fixed version is up there, Psion and Lordaerom helped me out on IRC.
Posted by gian [send private reply] at October 20, 2001, 03:03:05 PM
Oh good!
Register as a new user | |||||