Log In  

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..

P#79728 2020-07-21 19:28 ( Edited 2020-07-21 19:29)

1
 if (#wavestring==1) wavestring="0"..wavestring
P#79731 2020-07-21 20:07
1

You can append to strings using .. So, for instance:

first = "hello "
second = "world"
final = first..second
P#79730 2020-07-21 20:07

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 ^_^

P#79738 2020-07-21 22:00

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
P#79740 2020-07-21 22:48
1

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.

P#79743 2020-07-22 00:22 ( Edited 2020-07-22 00:31)

[Please log in to post a comment]