Array Issues

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
User avatar
~XUS~
Full Member
Posts:27
Joined:Tue Feb 01, 2005 9:08 pm
Contact:
Array Issues

Post by ~XUS~ » 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.
Justly is our impending doom thrust upon us, for mightily did we scar Gaia with our conquest out of laze, and so long coming has been our demise. You have been warned. The anguish is yours. -Aaron-

buff1

Post by buff1 » Thu Aug 18, 2005 10:51 pm

Show us at least a snippet of code that would represent your problem.

Dr_Davenstein
QBasic God
Posts:166
Joined:Tue Mar 25, 2003 12:45 am
Location:U.S.A.
Contact:

Post by Dr_Davenstein » Fri Aug 19, 2005 7:40 am

I wouldn't reccomend using DATA statements on the fly, but it sounds like you could just use RESTORE...

Code: Select all

Do
    RESTORE MyData

    For i = 1 to 2
        Read Temp
        Print Temp
    Next
Loop Until Inkey$=Chr$(27)

MyData:
DATA 25338
DATA 17475
See how it works? ;)
Come check out [url=http://www.freebasic.net/forum/index.php]FreeBASIC[/url]. The syntax is based on QuickBasic, but it expands to use pointers, operator overloading, etc... The list goes on and on!

Post Reply