Hi! I was working on a game and I was trying to make it so that for ex:
[
1,2,3,4,5,6,7,8,9,10,11,12 ... would be translated into
01,02,03,04,05,06,07,08,09,10,11,12 ...
]
and I was wondering how do you "apend" stuff to a string? I might be doing a doofus play but I forget some stuff about PICO-8 since I took a break from it : o
here's the code snipit I'm trying to figure out so far
wavenum+=1 wavestring=tostr(wavenum) if (#wavestring==1) add(wavestring,"0") |
(was wondering if you can use add() to add to a string maybe..
You can append to strings using .. So, for instance:
first = "hello " second = "world" final = first..second |
ooooooooooohohohhohohohohohhhhhhh..... ugh.
Thanks for pointing that out to me, just realized that that is the same thing I did in Löve2d so now I feel really dumb.. thanks again though I was stuck on that ^_^
Ok I got it working, it turns out I didn't even need to add anything to strings...
But I got a working counter!
function initwave() wavenum+=1 wavestring=tostr(wavenum) if #wavestring==1 then v=0 j=wavenum else v=tonum(sub(wavestring,1,1)) j=tonum(sub(wavestring,2,2)) end wavetextinit={ "i","c","o","m","i","m","g","!", "w","a","v","e",v,j } passbytimer=1 for i=1,8 do newtext(i*14,-24,0,3,wavetextinit[i]) end for i=9,14 do newtext(i*14-120,-20,0,3.3,wavetextinit[i]) end end |
Here's a really short way to add zeros at the beginning of numbers if you're still interested in doing that.
n=3 function _update() cls() print(sub("00"..n,-2),1,1,7) end |
Because of the negative index value in the sub() function, it will pull from the right side of the string instead of the left, so that your numbers always have the correct number of digits.
[Please log in to post a comment]