Hello! I've been doing the beginnings of tinkering around with TIC-80 after having used PICO-8 for about a month, and while I was looking through the documentation I realized I had run into quite a problem -- PICO-8 gives you 63 values to store user data to, and TIC-80 only gives you 7. This lead to an interesting problem, because one of the things I've been tinkering around with fantasy consoles for is a mini-RPG, complete with name entry.
In PICO-8 it was simple -- since you could only use capital letters I saved each letter as a number 1 to 26, then reconstructed the name with those values.
With TIC-80, I was scratching my head... until an idea hit me: You get 32-bit integers, which give you 2147483647 possible positive values (if the variables are signed, which I assume they are). And since TIC-80 supports lowercase letters, you can range 1 to 52, 53 if you allow for spaces. I decided to store the letters, grouped together, into integers. Since splitting 2147483647 into groups of 2 digits gives 21 47 48 36 47, I can't use the 21 (or 42 if unsigned) at the start. So I store 2 sets of 4 letters in integers ranging from 0 (nothing) to 53,535,353.
Here's the code to do this if you want to replicate the functionality -- you'll just need to implement these into save/load functions.
678 chars excluding comments.
ltrs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " local flr=math.floor --Convert 2 32-bit integers into one 8-character string function num2str(v1,v2) local n={0,0,0,0,0,0,0,0} local v2=v2 or 0 local o="" for i=8,5,-1 do n[i]=v2%100 v2 = flr(v2/100) end for i=4,1,-1 do n[i]=v1%100 v1 = flr(v1/100) end for i=1,8 do local l=n[i] if l>0 then o=o..ltrs:sub(l,l) end end return o end --Take a string (str) up to 8 chars and turn it into 2 integers function str2num(str) if #str>8 then error"String too long for str2num." end local s={} for i=1,#str do s[i]=ltrs:find(str:sub(i,i)) end local o={} local t="" local j=1 for i=1,#s do t=t..s[i] if i==4 then o[j]=flr(t*1) j=j+1 t="" end end if #s>4 then o[j]=flr(t*1) end o[2]=o[2] or 0 return o end
I'm sure there's a more efficient way to do this, but I'm used to the PICO-8 syntax. Also apologies for the variable shortening but that was a concession for the 64kb limit -- even though it would be best to do that after I was finished, for some reason I got into that mindset immediately and that's how I wrote it..
Variable 'o' is always "output", table 'n' are the numbers once split to turn into a string, table 's' is the opposite -- the numbers converted from their positions in the 'ltrs' string.
Hopefully people find this useful!
Edit Log:
There was an error being generated when you passed a 4-character string to str2num.
o[j]=flr(t*1)
became
if #s>4 then o[j]=flr(t*1) end
The above line was intended to write the value of 't' to the first number if the length was 1, 2, 3 or 4 characters and write to the second number in any other case. Thanks to not writing the logic properly 't' was trying to be converted from an empty string to a number and caused an error. This edit fixes that problem.