Cieroceramics [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=47197 loading external map data from string <p>So this will by my introduction. hello community. I need your help.<br /> so the game I created is a platforming game. for which I designed a external level editor in c++.<br /> my theory is. I can really only fit one level into the pico 8 map editor.<br /> but if I parse my map data as a string, despite adding a few extra thousand lines of code to my file, I will at least have a streamlined way to create and import levels. so far the level editor works great. I tell it how big I want the map and then once I have placed all my tiles I can save it to a text which just writes the x, y position and a type variable. 3 variables in total. so my output file ends up looking something like this</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>x y t 0 8 0 1 8 0 3 8 0 2 8 0 4 8 0 6 9 0 7 10 0 9 12 0 11 9 3 13 8 0 15 8 0 17 7 0 18 6 0</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>there has GOT to be a way to parse this data. in regular lua it would be something like </p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> platforms={} function _makeplatform(x,y,t) pf.t=t pf.x=x pf.y=y end function load_platforms(s) local str = s for line in string.gmatch(str, &quot;%.+\n&quot; do -- for every line in the string for a,b,c in string.gmatch(line, &quot;(%d+)(%d+)(%d+)&quot;) do --for every number in the line pf =_makeplatform(a,b,c) add(pf, platforms) end end k = 0 end level1 =[[ --copy and paste level output here ]] function _init() load_platforms(level1) end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <hr /> <p>the big kick in the pants being string.gmatch() not being in pico8.<br /> the good news is, I can basically output this information any way I want since I authored the editor. but whats the nicest way to have pico8 read it in?<br /> my best guess with sub() is to make each number 4 chars long so '2' would be '0002'. that way I can iterate through every 4 numbers. not sure if I like the sound of that solution. so here I am. </p> <img style="margin-bottom:16px" border=0 src="/media/47197/2_Screenshot 2020-09-17 234532.png" alt="" /> <p>this is the level editor. </p> <p>and <a href="https://cieroceramics.itch.io/runrun">here</a> is a very early release of my game. please excuse me for not uploading it to BBS. I am still figuring all this out but I swear once the game is playable again I will put it there. </p> <p>EDIT:<br /> I just added a Work in progress version of the game to BBS. so maybe it will become more clear what I am trying to accomplish. pease feel free to check it out. </p> <p> <table><tr><td> <a href="/bbs/?pid=81948#p"> <img src="/bbs/thumbs/pico8_runrun-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=81948#p"> runrun</a><br><br> by <a href="/bbs/?uid=47197"> Cieroceramics</a> <br><br><br> <a href="/bbs/?pid=81948#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=39632 https://www.lexaloffle.com/bbs/?tid=39632 Fri, 18 Sep 2020 04:12:47 UTC