Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Maps, and multidimensional arrays.
#11
Oh great, thanks a bunch! Hopefully that'll work
Reply
#12
Hmm.....

The first two would store the world location of the map,
and the last two would store the data needed to draw said map.

Ok, you will not have enough array space even with types, as you can't have arrays in types at least in qb45, and even then that will prolly count as >64KB.

What you want to do is to load maps in from a file and just have something like this:

Code:
fileName% = worldLocation%(x, y)
OPEN str$(filename%) FOR BINARY AS #1
a$ = " "
GET #1, , xmax%
GET #1, , ymax%
FOR x% = 1 TO xmax%
FOR y% = 1 TO ymax%
GET $1, , a$
worldMap%(x%, y%) = VAL(a$)
NEXT x%, y%
CLOSE
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#13
'$DYNAMIC worked, but now Agamemnus has got me curious. Looking at that little code you posted, I don't see how it would do anything more than simply storing one chracter in the worldMaps array, which does me no good. I'm going to bet it's something in the open statement that I don't quite understand. The str$() to be specific, what good does that do?
Reply
#14
(one thing I forgot to do is VAL() the a$, which makes it an integer instead of a string)

It loads the file into the map array. It doesn't store any characters, it loads up integers. The 'a$ = " "' is necessary to tell QB what the length of each piece of input is. (1)

Assuming that each map had a number associated with it, STR$() converts the value of the map into a string. Your directory would have these map files:

"1"
"2"
"3"
etc..

You can add a ".map" extension too if you want:
Code:
OPEN str$(filename%) + ".map" FOR BINARY AS #1

The map files would have this structure:
1) xmax%
2) ymax%
3) xmax% * ymax% bytes representing tiles
4) miscellaneous info if you need it.

To create the map files in the first place, all you have to do is change GET # to PUT # and switch it around:

Code:
fileName% = 1
xmax% = 100
ymax% = 100
OPEN str$(filename%) FOR BINARY AS #1
a$ = " "
PUT #1, , xmax%
PUT #1, , ymax%
FOR x% = 1 TO xmax%
FOR y% = 1 TO ymax%
a$ = STR$(worldMap%(x%, y%)): PUT #1, , a$
NEXT x%, y%
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#15
Great! Thanks a bunch
Reply
#16
Ok, I decided on the idea of using the .txt's to save the information for the maps. I use this loop to save information to the files:
Code:
OPEN "map" + STR$(mapNumber) FOR BINARY AS #1
FOR Y = 0 TO 19
  FOR X = 0 TO 31
   READ z
   PUT #1, , z
  NEXT X
NEXT Y
CLOSE #1

DATA .....

It succesfully saves the information of the map into a text file, which I can then use the same loop with a GET instead of a PUT to see all the numbers, however when I use it in my actual game it will only work with map1.txt. All the other numbers don't work. I have each map assigned a number in a 10 x 10 array called allMaps(1 TO 10, 1 TO 10). The numbers go from 1 to 100 across and then down. ie:
1,2,3,4,5,6,7,8,9,10
11,12,13....

I use this array to get a number which then corresponds to one of the map files I previously saved, but on any map but #1, all I get are 0's.

I am completly stumped, any ideas?
Reply
#17
Hmmm.....

Of course I forgot a "little" detail...

The STR$() converts to a number and a space in front of it, if it is a positive number... If it's negative it puts the "-" symbol there. You might be saving to the same file since DOS doesn't like spaces in filenames......

Try using LTRIM$(STR$())...
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#18
Ah, that was it. I figured it out right before checking the board again, but thank's anyway!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)