The data command is immensly usefuly in certain methods of tileing a map. Without it you would have to use an array and manually set each sprite for each tile, as you can guess even a small 10x10 map would be 100 lines of code, for just one map! data can make this go much faster than that, as you can "draw" the map in the editor as long as you know your sprite frames. Allow me to explain
lets say for simplicity sake you have a simple 2x1 tileset. One tile for grass, and one for a wall.
one method for setting up your map is as follows(assumiong frame 1 is grass and frame 2 is wall)
load image "tileset.bmp",1
for n=1 to 100`creats 100 sprites
create animated sprite n,"tileset.bmp",2,1,1
next n
`set up array sprites
dim map(100,1)
map(1,1)=1
map(2,1)=1
map(3,1)=1
map(4,1)=2
map(5,1)=2
map(6,1)=1
as you can see that method would take quite some time as you would have to define 100 array values for each map you made. there has to be an easier way right?
...
..
...
RIGHT!
using the "data" "read" commands you can literally draw the map, the load it as sprite data. heres the syntax
data data_1,data_2,data_3,ect.....
with this method you would draw the 10 by 10 map you want as follows
data 1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1
data 1,1,2,2,2,2,2,1,1,1
data 1,1,2,1,1,1,2,1,1,1
data 1,1,2,1,1,1,2,1,1,1
data 1,1,2,1,1,1,2,1,1,1
data 1,1,2,2,1,2,2,1,1,1
data 1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1
now thats much simpler right? you can actually see the map where 2 = walls and 1 = grass. But how do you read this value?
using the read command!
read var
this allows you to read the values from left to right top to bottom of the data . and store it to a variable.
heres an example of the use of both:
data 1,2,3,4`first line of data
data 5,6,7,8`second line of data
dim array(8)`a variable to hold the data
for n=1 to 8
read array(n)
print array(n)
next n
This would create a data set holding the numbers 1-8. it then sets all variable places to hold each data in order. then it prints the data to screen. Resulting in:
Quote: "
1
2
3
4
5
6
7
8
"
but how does this allow you to make a game? think about it. if you draw the map using a data set. then load that into a array(data_set_width*data_set_height). Then you just created a grid of game data that holds the sprite value. Simply draw that to the scrren using whatever method you prefer and Voila! much faster map makeing!
~Vesper103
[Challange]
Create a sprite sheet of a 5x5 black and 5x5 white tile. then using data & read. draw a picture on the screen using those two tiles.
(hint you will need to create a loop to create as many sprites as you have tiles)
post your code in this thread
[edit]
Dont put the variable to be read to in parenthsis, that will cause your code to not run. Also below this i will add a full program to draw a basic 5x5 map using data read and the 2x1 spriteset "tileset.bmp"
set display mode 150,113,16
sync on
sync rate 60
backdrop off
hide mouse
load image "tileset.bmp",1
for n=1 to 100
create animated sprite n,"tileset.bmp",2,1,1
next n
dim sprites(100)
data 1,1,1,1,1,1,1,1,1,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,1,1,1,1,1,1,2,1
data 1,2,1,1,2,1,2,2,2,1
data 1,2,1,1,2,1,1,1,1,1
data 1,2,1,1,2,1,1,1,1,1
data 1,2,1,1,2,1,1,1,1,1
data 1,2,2,2,2,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1
for n=1 to 100
read z
sprites(n)=z
next n
do
`can you fix the position sprites loop to compress it to a much smaller size?
`position sprites
for n=1 to 100
if n<11 then sprite n,n*10-10,0,1
if n>10 and n <21 then sprite n,((n-10)*10)-10,10,1
if n>20 and n <31 then sprite n,((n-20)*10)-10,20,1
if n>30 and n <41 then sprite n,((n-30)*10)-10,30,1
if n>40 and n <51 then sprite n,((n-40)*10)-10,40,1
if n>50 and n <61 then sprite n,((n-50)*10)-10,50,1
if n>60 and n <71 then sprite n,((n-60)*10)-10,60,1
if n>70 and n <81 then sprite n,((n-70)*10)-10,70,1
if n>80 and n <91 then sprite n,((n-80)*10)-10,80,1
if n>90 and n <101 then sprite n,((n-90)*10)-10,90,1
next n
`end position loop
for n=1 to 100
play sprite n,sprites(n),sprites(n),1
next n
sync
loop
Your signature has been erased by a mod - please limit your signature to 600x120