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):

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

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?

for i=1,#str do
    --did you want to set x and y somehow?

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)

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]

Follow Lexaloffle:          
Generated 2024-02-26 21:08:48 | 0.006s | Q:12