Log In  

Help with tables

So I have a function for creating text with sprites (I'm sure people have done this already, but i specifically want help with one thing):

charspr{74,75,76,77,78,79,90,91,92,93,94,95,106,107,108,109,110,111,122,123,124,125,126,127,138,139,140,141,142,143,154,155,156,157,158,159,170,171,172,173,174,175,186,187,188}
charname{"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","0","p","q","r","s","t","u","v","w","x","y","z",".","-","!","\"","\'",",",":",";","𝘹","?","1","2","3","4","5","6","7","8","9"," "}
for i=0,#str,1 do
 spr(charspr[charname[sub(str,1,nil)]])
end

Now the long tables charspr and charname are supposed to give out the id of a sprite. (I use charname to know the id of an item from charspr)
From my testing I found out that the problem (the one I want help with) is when I try to call charname[<a letter from sub()>]. Apparently it gives out [nil], but what i thought it would do is something like a block from Scratch:
(item # of (< item>) in [< list>]),
but apparently it doesn't. So I'm asking: if anyone would know about a workaround or how to do it properly.

P#129129 2023-04-29 13:25

does this do what you want?

charspr={a=74,b=75,c=76,...
for i=1,#str do
  spr(
    charspr[sub(str,i,i)]
    --did you want to set x and y somehow?
    )
end

edit: your charname table doesn't work the way you want because it associates numbers with letters, not vice-versa.

P#129133 2023-04-29 15:34 ( Edited 2023-04-29 15:38)
1

Thx packbat i didn't realise that this is possible

P#129176 2023-04-30 08:05

Tables aren't explained much in the PICO-8 manual, but there's some information in the Lua manual - it takes some work to parse, though.

P#129199 2023-04-30 20:46 ( Edited 2023-04-30 20:46)

[Please log in to post a comment]