Data

Blitz3D Forums/Blitz3D Programming/Data

wizzlefish(Posted 2004) [#1]
There are still some key points of Blitz that I haven't figured out yet. One of them is "Data." Out of the examples that I have looked at, it looks as if you just call "Data" and voila! The program works. Is this the case? I don't believe so.

I have absolutely no clue about the mysterious "Data" function, and I suppose it is useful (although I can't exactly figure out why.)

So am here to ask two questions:

1. What is the syntax of Data and what is it used for?

2. How do you refer to a Data stream that you've created?


Ross C(Posted 2004) [#2]
Using the data command you can read in..well..data :o) from within your program. This data usually gives positions for a new level, and entity names to be loaded in..etc etc


Ross C(Posted 2004) [#3]
You would usually have a function called load level. The function reads in the first level from data statements. say something like

Data 1 ; level number
Data 4 ; number of entities
Data 30,0,40
Data 90,0,60
Data 330,0,40
Data 10,0,140

Data 2 ; level number
Data 2 ; number of entities
Data 130,10,120
Data 70,30,110



jfk EO-11110(Posted 2004) [#4]
I love such questions, really.

Anyway. Data lets you store data inside the code without to preassign it to a variable. Example

restore pink
read red
read greed
read blue
color red,green,blue
print "hello world"

restore yellow
read red
read greed
read blue
color red,green,blue
print "now somethin completely diffrent :P"

.pink
Data 255,0,255

.yellow
data 255,255,0

theoreticly you could use Data to convert an Image to Data and then create it on the fly. But there's a problem, it will use much more RAM than if you simply load it from the HD.

Data is a very old Basic Command. I guess it comes from the Assembler Languages "Data Segment". In prehistoric times a program had a Text-Segment (machinecode), a data segment (data) and some other segments, and all the segments where limited to 64 Kilobytes due to the 16 Bit adressing methods of those dino-chips. Anyway, Data still may be useful in some cases.


BlackD(Posted 2004) [#5]
Data is good for storing lots of strings or numbers that aren't going to change.. for instance in one of my progs, I have:


By simply listing the data and READing it, it's a lot quicker (and CLEANER) than typing out:
bit.pass=new pass
bit\rll=0
bit\rll2=1
bit\bitmask$="11011011 01101101 10110110"
bit\hex$="0xDB 0x6D 0xB6"
bit\ETC ETC ETC :)
repeat ad nauseum for every data statement in the program. Now that's only a small data set, but some programs use much larger data sets. Data isn't AS necessary as it used to be. On the old Apple ][ for instance, it was hard to read any data information from an external file - so all your info (image drawing data, conversation data, etc) had to be stored in the one program. Thats where data was useful.

It still is useful, as I demonstrated above - but not as much so, since we now can read/write from multiple files simultaneously without any trouble. Basically - it all depends on how much data you're using. If you're using 0-100 lines of data info - just shove it into your program as DATA statements. its pointless to add ANOTHER file to the distro just with 50 lines of data that could easily be packed into the main code. If you're going over 100 lines of data you need, consider storing it in an external file. :)

Happy coding! ;)

+BlackD