? String Mapping ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

String Mapping

THIS IS OBSOLETE AND I RECOMMEND THAT YOU SHOULD NEVER DO THIS! THERE ARE BETTER WAYS! Last night (March 3rd, 2016), I found out how to store map data into a TXT file. There are so many reasons to use TXT instead of DAT for storing map data, but with every way of doing something, there are always cons to using it. Here are the pros and cons of using TXT files to store map data. Pros:
  1. *You can track the progress of loading the map
  2. *You can decide to load a part of the map
  3. *It's easy to understand
  4. *It's perfect to use if you want custom maps in your game (like Super Mario Maker)
  5. *It has virtually infinite amount of separate characters to save the map with
  6. *You can save more than one layer of a map in the TXT
  7. *You are able to save other things in the TXT as well as the map data (such as the map's name)
  8. *It's easy to extract data
  9. *There are many more pros to using this, but I can't name them all
Cons:
  1. *Takes up more space
Now, onto the good stuff. Saving a map as a TXT file: FOR BGY=0 TO 63 FOR BGX=0 TO 63 NUM=BGGET(0,BGX,BGY,0) MAPDATA$=MAPDATA$+CHR$(NUM+14) NEXT NEXT FOR BGY=0 TO 63 FOR BGX=0 TO 63 NUM=BGGET(1,BGX,BGY,0) MAPDATA$=MAPDATA$+CHR$(NUM+14) NEXT NEXT SAVE"TXT:TESTMAP",MAPDATA$ This code was made specifically for a 64x64 map, but you can change it to what ever size you like. Anyways, what this does is scans the screen for the BG tiles and converts it into a string. It scans each tile one at a time, but it's actually really fast. The CHR$(13) bug is also avoided completely due to it increasing the CHR$() by 14. Simple right?! I almost forgot to mention, you have to have BG tiles on the screen in order to save it as a TXT file. Therefore, you can make a map and save it using DAT and then load it and save it as a TXT. Loading a map from a TXT file: LOAD"TXT:TESTMAP",0 OUT MAPDATA$ BGSCREEN 0,127,127 BGSCREEN 1,127,127 FOR NUM=0 TO 4096 BGPUT 0,BGX,BGY,ASC(MAPDATA$[NUM])-14 BGX=BGX+1 IF BGX>=64 THEN BGY=BGY+1:BGX=0 BGNUM=0 NEXT BGX=0:BGY=0:NUM=4095 FOR NUM=4095 TO 8192 BGPUT 0,BGX,BGY,ASC(MAPDATA$[NUM])-14 BGX=BGX+1 IF BGX>=64 THEN BGY=BGY+1:BGX=0 BGNUM=0 NEXT Ok, now things get a little bit more complicated but it's still simple. What this does is it loads the TXT file we previously made and then takes one character out of the string at a time, scans them, and then puts them in their proper place. As you can see, string mapping is quite simple. I initially made this so i can extract map collision data, but quickly found other uses for it. I hope you found this useful!!! I have begun remaking this engine for my new game on PC. I'll post a tech demo of both the PC and SB versions of this engine sometime.
Author
RNGesus
Updated
Rating
6 votes
Categories
Keywords
  • string
  • mapping
  • txt
  • map
  • bg
  • layers
  • custom
  • data
  • text
  • store
  • storage
  • extract
  • encrypt
  • decrypt
9 Comment(s) 12Me21 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself DIM MAPDATA[0] BGSAVE 0,MAPDATA SAVE "DAT:MAP",MAPDATADIM MAPDATA[0] LOAD "DAT:MAP",MAPDATA BGLOAD 0,MAPDATA RNGesus RNGesus Of course it's a better solution. In fact, now I mainly use arrays for storage. I was naive and stupid when making this thing. There are much better ways and I was really lying to myself about those so called "benefits" to using strings for storage. random_god random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Video Games I like to play video games! Hobbies ill try it this is perfect, im trying a metroid maker! thx ill try it! Minxrod Minxrod Summer 2016 Contest Participant I participated in the SmileBASIC Source Summer 2016 Contest! Programming Contest Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Pokemon Is Awesome! I love Pokemon! Express Yourself Optimization idea: You have FOR BGY=0 TO 63 FOR BGX=0 TO 63 NUM=BGGET(0,BGX,BGY,0) MAPDATA$=MAPDATA$+CHR$(NUM+14) NEXT NEXT FOR BGY=0 TO 63 FOR BGX=0 TO 63 NUM=BGGET(1,BGX,BGY,0) MAPDATA$=MAPDATA$+CHR$(NUM+14) NEXT NEXT SAVE"TXT:TESTMAP",MAPDATA$ but if you combine the two loops with another FOR statement: FOR LYR=0 TO 1 FOR BGY=0 TO 63 FOR BGX=0 TO 63 NUM=BGGET(LYR,BGX,BGY,0) MAPDATA$=MAPDATA$+CHR$(NUM+14) NEXT NEXT NEXT SAVE"TXT:TESTMAP",MAPDATA$ it can accomplish the same thing with less code. Just a thought :) RNGesus RNGesus I already know about that. I used that way to make it a user defined command. Either way, you'll have to run it multiple times. RNGesus RNGesus I was able to increase the loading speed tenfold, thanks to incvoid and 12me21 for helping me out. EDIT:Because of this, I can make the maps much, much, much larger in the game I'm making. incvoid incvoid ...I did FOR I = 0 TO 65535 IF ASC(CHR$(I)) ==I THEN ?"UNMAPPABLE",I NEXT nothing prints, indicating that asc is returning the correct value(0-65535). Anything over 65536 and asc doesn't reflect the "i" properly. so the whole for loop... FOR BGNUM=0 TO 16384 IF MAP$==CHR$(BGNUM) THEN BGPUT 1,BGX,BGY,(BGNUM-14):BGNUM=16384 NEXT probably can just be changed to BGPUT 1,BGX,BGY,asc(map$)-14 and bgnum can be tossed. Ya probably already did that, and that's where you picked up the speed boost, and this post is old copy pasta RNGesus RNGesus I tried that, but a 64*64 two layered map has too much information for that (over 8000 characters). 16bitcoder 16bitcoder Helpful!