DefData, ReadData... help.

BlitzMax Forums/BlitzMax Beginners Area/DefData, ReadData... help.

Apollonius(Posted 2006) [#1]
Using ReadData how can I read a specific cell?

Example

#setting
DefData 0,2,3,5,6

Let's say I wana read the 5th cell, what would you do.

Basicly Im trying to access #map_main_data get 3rd/4th cell which is 10 to determine how many cells horizontal and then vertical #map_main_layer1 has.

#map_main_data
DefData 32,32,10,10,2

#map_main_layer1

DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0



xlsior(Posted 2006) [#2]
The easiest way is probably to use a special value to indicate the end of your dataset, and then read the data and put it in an array until it hits your end value... You can then check the specific cell by looking what value that position in the array has.


Jesse(Posted 2006) [#3]
Data is not effectively read randomly. Tthe best way to do it is to store it in to an array like this:



Jesse(Posted 2006) [#4]
another example is to use types like this:


edited: some stuped syntax errors I made corrected. I am surpriced the compiler did not catch them when I ran it.


Apollonius(Posted 2006) [#5]
I like your first example, I'm new to the BMAX syntax I used to use B+. I'm pretty much a nooblet and it took me abit of time to understand it. So basicly your storing ALL the data into two arrays.

I like your first example but it has a syntax error in it could you correct it?

"index array element beyond array length"


ImaginaryHuman(Posted 2006) [#6]
That's what labels are for, I thought, it allows you to set the position where you read from. You could scatter labels thoughout your data at periodic places and then jump to the offset you want and seek from there.


Apollonius(Posted 2006) [#7]
Well basicly the maps will be read from external files and map size will differ from maps to maps, I'm not sure how labels work yet but if it is what it sounds to be, it'd be a large hassle to work with those, no?

*pokes jesse for a code fix* ;D


amonite(Posted 2006) [#8]
.nonsense removed


Apollonius(Posted 2006) [#9]
uh?


amonite(Posted 2006) [#10]
uh?

from wiki : Nonsense is an utterance or written text in what appears to be a human language or other symbolic system, that does not in fact carry any identifiable meaning. Nonsense is generally used by school-age children as a form of communication among their peers.

@Kaisuo i just edited my post because i thought what i wrote was stupid :)


Jesse(Posted 2006) [#11]
I tried it again and it works fine maybe you didn't copy it correctly


Jesse(Posted 2006) [#12]
I tried it again this time in debug mode and it tracked the error this time. is a stuped mistake on my part:

when I created array info, I made it 5 elements in size. that number is stored in the "length" part of the array.
But when the program tried to read the data with the for loop, it was reading 0 to 5 which is 6 elements. The true array size is 0 to 4 which is five elements. So the for loop should read like this:
For Local i= 0 To info.length-1

the same go for the other 2 "for" statements
I fixed it in the second example but didn't pay attention on the first one.
I have edited the code and it works fine now.

I guess it only catches the error in debug mode. weird!


impixi(Posted 2006) [#13]

Basicly Im trying to access #map_main_data get 3rd/4th cell which is 10 to determine how many cells horizontal and then vertical #map_main_layer1 has.



This is how we used to do it in the old days:



EDIT: Added some comments to the code.


Jesse(Posted 2006) [#14]
yes it is basically the same thing. yours is a better method for readability purpose. I was just illustrating the use of arrays.