Array Bug - I declare an array and then two multidimensional arrays then open a file and read the first array, then two multidimensional arrays all from a sequential file.
So when I read the file, I read a in a string that belongs to the first array. Then I read in a number that is an element in the first multidimensional array, then I read in a number that is an element in the second multidimensional array, all from the same file.
If I print out all of the information in a for next loop:
for h = 1 to 6
print (a$[h])
for h1 = 1 to 10
print (x[h,h1])
print (y[h,h1])
next h1
next h
I can see all of the elements in all arrays are present.
However I cannot access one element in either of the multidimensional arrays individually.
If I leave out or remark out the print(a$[h]):
for h = 1 to 6
// print (a$[h])
for h1 = 1 to 10
print (x[h,h1])
print (y[h,h1])
next h1
next h
Then all I get is zeros for the x[h,h1] and the y[h,h1].
and if I try to use any of the elements of either of the two multidimensional arrays individually I get a zero as in:
SetSpritePosition( 1, x[h,h1], y[h,h1]. The sprite ends up in the 0,0 position on the screen, always for every element of each of the arrays.
Unless I refer to the string in the standard array, in order, the multidimensional arrays have no return value.
Here is the data in my file, "pos.dat":
Level 1
295
30
25
115
155
70
20
330
230
175
155
160
230
165
25
45
295
25
30
115
Level 2
280
440
15
440
130
300
0
0
30
245
90
390
240
350
290
25
170
290
60
325
Level 3
290
455
230
360
50
330
170
290
140
445
230
230
35
200
10
445
270
340
85
380
Level 4
0
0
295
100
180
65
65
100
290
155
295
390
215
70
295
105
240
275
195
25
Level 5
0
0
5
435
55
260
210
70
290
100
35
265
235
345
265
455
290
15
45
300
Level 6
295
455
280
5
230
240
30
440
200
230
265
70
265
340
85
390
290
100
55
0
Here is some sample code that demonstrates the problem:
dim homeX[20,10] as integer
dim homeY[20,10] as integer
dim level$[20]
SetDisplayAspect( 0.66 )
gosub _readData
do
for h = 1 to 6 rem should be 20
rem print(level$[h])
for h1 = 1 to 10
print(homeX[h,h1])
print (homeY[h,h1])
next h1
next h
sync()
loop
_readData:
OpenToRead( 1, "pos.dat" )
if FileIsOpen( 1 )
for h = 1 to 6 rem should be 20
level$[h] = readString(1)
for h1 = 1 to 10
x$ = ReadString( 1 )
y$ = ReadString( 1 )
homeX[h,h1] = val(x$)
homeY[h,h1] = val(y$)
next h1
next h
endif
closeFile(1)
return
Notice that the "print(level$[h])" line is remmed out.
When your run the code with this line remmed out, the print statements return all zeros.
If you delete the "rem" on the front of the line, you get the values for each element of the arrays.
I have also attached the "pos.dat" file
I store the data as strings in the file. This way I can easily read and write the data with "notepad".
I then read in each value and convert it from a string to a value then assign it to an element of the array. I've done this a lot in DBPro and other development environments so this should not be causing the problem.
I've tried several things to work around the problem with no success. I tried taking the string out of the file "level1", etc. and I've tried separating the two sets of array data into separate files. None of this works. When I try to get the info from the array, it holds nothing.