ord( string, [index], [num_results] )

ord "ordinal" get ordinal character code
string one or more characters that you want to convert
index (optional) the number of characters from the start of the string to start converting.
num_results (optional) a number of total characters in the string to convert.

This function will return a string with the single character that is associated with the ordinal number a; or it will return a string with multiple characters if multiple values were given as arguments.

What is an ordinal character code?

An ordinal character code, often referred to as an "ordinal number", is a way to represent the position or order of something in a list or sequence. It's a numerical value that tells you where a particular item stands in relation to others. In this case, the list is of characters (such as letters, numbers, punctuation marks, and some control characters like newline and tab).

You may have heard of something called "ASCII" (American Standard Code for Information Interchange). It is a character encoding standard that uses a sequence of numbers to represent characters in computers. In ASCII, each character is assigned a unique numeric value or "character code". For example, the ASCII code for the uppercase letter 'A' is 65, while the code for the lowercase letter 'a' is 97.

PICO-8 has its own sequence of characters in its own order. We call these "P8SCII" (PICO-8 Standard Code for Information Interchange) for fun. See list of all P8SCII numbers and characters.

For example:

a = "?"

print( ord(a) )

string = "pico"
a,b,c,d = ord( string, 1, 4 )


You may want to encode a string as ordinal numbers and then decode later. For example:

string = "pico"
a,b,c,d = ord(string,1,#string)

print("chr | ord",12)
print("p  =  "..a,7)
print("i  =  "..b)
print("c  =  "..c)
print("o  =  "..d)

print( chr(a,b,c,d),11 )


10 Sep 2023