CHR


chr( a, [ b, c, ... ] )

chr "character"
a an ordinal character code
[b,c,...] (optional) you can provide as many ordinal values as you'd like, and the function will return them in a single string in the same order they were given.

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 = 135 --heart

print( chr(a) )

a = 135 --heart
b = 143 --pico-8 diamond

print( chr(a,b) )

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 )


417

10 Sep 2023

Font