LoginLogin
Might make SBS readonly: thread

How does DATA work?

Root / Programming Questions / [.]

GreedyGoat8Created:
I’m currently having trouble understanding some areas of the DATA command. I know how title DATA and map DATA works but I don’t know how it works whenever it just a bunch of numbers. I guess it would be easier if I knew the entire definition of DATA(maybe someone could tell me.) Anyway, here’s an example of what I’m not understanding.
SPDEF “@SPDATA”

@SPDATA
DATA 256,80,16,16,8,8,1
DATA 304,80,16,16,8,8,1
DATA 0,256,16,16,8,8,1
DATA ...
DATA ... 
It’s something like that. I was wondering how this worked and was trying to understand it so I could maybe use it in the future. Help is greatly appreciated, thank you.

DATA itself is very simple, it's just a way to specify number or string data that can be read using a variety of commands (READ, COPY, SPDEF, etc.). DATA doesn't care about the format of the data you give it, what the data actually means depends on whatever happens to be reading the data. In other words, if you want to know how SPDEF uses DATA, you need to look at SPDEF's help info. Here's an example of using DATA:
RESTORE @MYDATA 'Start reading from @MYDATA
READ X  'Read a number from data and set X to it
PRINT X 'Prints 123
READ X  'Read the next number
PRINT X 'Prints 456

@MYDATA
DATA 123,456,789
Note that DATA doesn't care if it's on separate lines or not. These are equivalent:
DATA 123,456,789

DATA 123
DATA 456
DATA 789

I’m currently having trouble understanding some areas of the DATA command. I know how title DATA and map DATA works but I don’t know how it works whenever it just a bunch of numbers. I guess it would be easier if I knew the entire definition of DATA(maybe someone could tell me.) Anyway, here’s an example of what I’m not understanding.
SPDEF “@SPDATA”

@SPDATA
DATA 256,80,16,16,8,8,1
DATA 304,80,16,16,8,8,1
DATA 0,256,16,16,8,8,1
DATA ...
DATA ... 
It looks like you have the correct way to call the @SPDATA label for definitions, but the DATA commands themselves looks like they don't hold enough information for the sprite definitions. SPDEFs need the sprite number, U coordinate, V coordinate, width, height, origin X, origin Y, attribute (optional). You are missing a number. Try this:
@SPDATA
DATA 0,256,80,16,16,8,8,1
DATA 1,304,80,16,16,8,8,1
DATA 2,0,256,16,16,8,8,1
DATA ...
DATA ...  
The code above adds the sprite number at the beginning (starting with 0). Note that this will override the default sprite template so the default sprites for 0, 1, 2, etc will be whatever sprite you've defined it to be.

Wow, thanks for the great information you guys! I now have a greater understanding of DATA. I mainly was confused with the “how do you know what to put and where to put it,” but now I pretty much understand. Thanks for the great information.

The correct way to use DATA for SPDEF is:
SPDEF @SPDATA

@SPDATA
DATA 3 'number of definitions
DATA 256,80,16,16,8,8,1 'definition 0
DATA 304,80,16,16,8,8,1 'definition 1
DATA 0,256,16,16,8,8,1 'definition 2
Also, don't listen to the manual when it says to use "@SPDATA" rather than @SPDATA, because they're exactly the same thing (In early versions of SmileBASIC, this didn't work)

The correct way to use DATA for SPDEF is:
SPDEF @SPDATA

@SPDATA
DATA 3 'number of definitions
DATA 256,80,16,16,8,8,1 'definition 0
DATA 304,80,16,16,8,8,1 'definition 1
DATA 0,256,16,16,8,8,1 'definition 2
Also, don't listen to the manual when it says to use "@SPDATA" rather than @SPDATA, because they're exactly the same thing (In early versions of SmileBASIC, this didn't work)
So how would I load the spdata on the screen and how do I save it as a sprite?