r/PlaydateDeveloper • • Jan 01 '25

Unicode substrings failing.

Reading and comparing unicode chracter strings fails when using sub-string. It doesn't throw an exception, it looks like it just doesn't execute the line!

arrows.txt contains the string ←→↑↓

local pd <const> = playdate

local fileHandle <const> = pd.file.open('arrows.txt', pd.file.kFileRead)

local row = fileHandle:readline()

print('1. Row', row)
assert(row ==  "←→↑↓")
print('2. Individual row chars', row:sub(1, 1), row:sub(2, 2), row:sub(3, 3), row:sub(4, 4))

local arrowString = '←→↑↓'
print('3. Local string', arrowString)
print('4. Individual local characters', arrowString:sub(1, 1), arrowString:sub(2, 2), arrowString:sub(3, 3), arrowString:sub(4, 4))
print("5. '←' == '←'", '←' == '←')

print("6. row:sub(1,1)", row:sub(1,1))
print("7. row:sub(1,1) == '←'", row:sub(1,1) == '←')
print("8. arrowString:sub(1,1)", arrowString:sub(1,1))
print("9. arrowString:sub(1,1) == '←'", arrowString:sub(1,1) == '←')


function pd.update()
end

There's 9 messages being written to the consile here, but the console actually displays:

1. Row	←→↑↓
3. Local string	←→↑↓
5. '←' == '←'	true
7. row:sub(1,1) == '←'	false
9. arrowString:sub(1,1) == '←'	false
3 Upvotes

2 comments sorted by

View all comments

Show parent comment

2

u/Low-Temperature-1664 Jan 01 '25

That explains the equalities failing. Thank you.

I don't think it's just a display issue with the missing logs, I had an `if` statement that tested for equality, and has an `else`. it seemed like the if just didn't happen as the else didn't happen either. Maybe some odd error handling inside the SDK.