Hi
Could someone kindly tell me how to for loop through each char of a string? I'm unsure how this is done with pico 8.
P#94031 2021-06-25 19:23
given string s,
for i=1,#s do local c = sub(s, i, i) -- do stuff with c end |
I put "local" here because it's typically faster that way, but it is optional.
P#94034 2021-06-25 19:38
Yes, though I'm basing that claim on lua in general more than Pico-8. From what I've read, local variables in general tend to be faster to access. My guess is it's because underlying code has to wade through all the variables and functions available in the scope being used, and local scope has less to wade through.
P#94038 2021-06-25 21:18
Here is a pretty decent explanation of it: https://stackoverflow.com/questions/9132288/why-are-local-variables-accessed-faster-than-global-variables-in-lua
P#94047 2021-06-26 00:15
[Please log in to post a comment]