Array Issues
Posted: Thu Aug 18, 2005 9:53 pm
I have the following map system for my RPG: the world map is divided into smaller, screen-sized maps, and the world map consists of 20 by 15 of these. They are each labelled by four digits, two for the x-coordinate (starting at 10), and two for the y-coordinate (starting at 10), and thus, for instance, 1010 is in the upper left corner and is right above 1011. In this way, the x and y coordinates of the current screen-sized map can be changed by adding or subtracting 100 or 1, respectively.
The problem arises when tring to load the data for each of these maps (which reside within the actual source code) into the "map" array. As soon as the character moves down off the screen, 1 is added to the map number, changing 1010 to 1011, and it copies the data for 1011 into the map variable. It then loads the 1011 map without a problem. However, when I try to backtrack to 1010, the program errors, and remarks that it is out of data. I am not sure, but I believe that this may be due to the fact that I have no command to clear the "map" array before loading the new data, but I have looked into this, and cannot find a solution myself. Please help, if you know how I could solve the problem, or perhaps if you know how I could write the arrays to a file and load them at need (I feel that might work, but I am not adept in the art of loading and saving).
Thanks.
The problem arises when tring to load the data for each of these maps (which reside within the actual source code) into the "map" array. As soon as the character moves down off the screen, 1 is added to the map number, changing 1010 to 1011, and it copies the data for 1011 into the map variable. It then loads the 1011 map without a problem. However, when I try to backtrack to 1010, the program errors, and remarks that it is out of data. I am not sure, but I believe that this may be due to the fact that I have no command to clear the "map" array before loading the new data, but I have looked into this, and cannot find a solution myself. Please help, if you know how I could solve the problem, or perhaps if you know how I could write the arrays to a file and load them at need (I feel that might work, but I am not adept in the art of loading and saving).
Thanks.