LoginLogin

Map DATA array with comas

Root / Programming Questions / [.]

Joshuaham123Created:
If you go to this page you will see a array with ASCII characters. I know there is a way to do this with numbers but also with comas so that you can do numbers larger than 9. Does anybody know a thread for this or a way to do this? Please help. If I didn't do a good job explaining then I can do try to do it better.

You'll have to do it better I reckon. Do you mean like DATA?
DATA 4,5,9,0,8,1,...

Sorry. So I want to spawn a map in so that I can have a sprite move around on it. Dont worry about the sprite. I want it to be written with Data 4,58,1,82 Data 4,7,8,8 Data 5,7,57,4 Data 6,72,3,1 Similar to the one in the link but with comas.

There is no link in your original post.


sorry

So, you want to use numbers in string format, though have their values be larger than 9? Do you need it to be in a string? Numbers and strings can become interchangable with VAL() and STR$(). The best way to store numbers with DATA, especially those larger than 9, is to store them literally, ex. DATA 4, 58, 1, 82.

You could do something like this:
VAR MAXH=5:VAR MAXW=5:DIM MAP[MAXH,MAXW] 'a small map for demonstration purposes
RESTORE @MAP
FOR I=0 TO MAXH-1
 FOR J=0 TO MAXW-1
  READ MAP[I,J]
 NEXT
NEXT

DrawMap


DEF DrawMap
 FOR I=0 TO MAXH-1
  FOR J=0 TO MAXW-1
   IF MAP[I,J]==0 THEN BGPUT 0,I,J,'TILE
   IF MAP[I,J]==1 THEN BGPUT 1,I,J,'TILE
   IF MAP[I,J]==56 THEN BGPUT 2,I,J,'TILE
   'etc
  NEXT
 NEXT
END

@MAP
DATA 0,0,0,0,0
DATA 0,1,1,1,0
DATA 0,1,1,1,0
DATA 0,1,56,1,0
DATA 0,0,0,0,0
If you need to put BG tiles across different layers with one number, that is simple to do as well.
'In DrawMap function under nested FOR loop
 IF MAP[I,J]==4 THEN
  BGPUT 0,I,J,'TILE
  BGPUT 1,I,J,'TILE
  'etc
 ENDIF
You may have to play around with this a bit, I wasn't able to test it because I am away from my 3DS but it is very similar to the link you had mentioned but with numbers instead of strings.