Log In  

Some more scratch blocks that I don’t know if they’re in pico 8

If you don’t know what they do:

-length of(“apple”):
-takes the input of a string and outputs how many characters are in that string (for example, length of(apple) = 5

-length of(listname):
-takes the input of an array and outputs how long that array is (for example:

X={1,2,5,3,7,}
Z=length of(x)
//Z == 5

)

So if you know if these are in pico 8 and what they are please tell me

P#122280 2022-12-12 14:28 ( Edited 2022-12-12 14:29)

3

You can use #X to get the count of elements in this particular table, but there are cases where this may not do what you expect. For example, if you have:

X={1,2,3,nil,nil}
print(#X)

That will print 3 rather than 5, so just be aware of that. It also works differently for tables that are dictionaries, such as:

a={}
a.one=1
a.two=2
a.three=3
print(#a)

That will print 0.

The same # operator works for strings, so if you do:

a="apple"
print(#a)

That will print 5. Hope that helps!

P#122282 2022-12-12 14:42

@2bitchuck gave a great answer. @my_name_is_doof, I'd suggest taking some time to read the User Manual, as this information is in there:
https://www.lexaloffle.com/dl/docs/pico-8_manual.html

Also, there is a great wiki that has thorough reference pages for everything that has to do with coding on Pico-8. Here is the Lua reference page, which also tells about this # operator:
https://pico-8.fandom.com/wiki/Lua

Here is the main page of the wiki. You should bookmark it!
https://pico-8.fandom.com/wiki/Pico-8_Wikia

P#122286 2022-12-12 15:40

Thank you @2bitchuck !

P#122288 2022-12-12 18:28

[Please log in to post a comment]