Search code examples
pythonunicodeutf-8renpy

Getting non-ASCII characters to work in Ren'Py functions


I'm translating a Ren'Py game, which involves redefining a function that converts numbers to written-out words in a particular language. Those strings are then handled and inserted into the game text by the main code of the game (which I can't modify).

My problem is that when I return strings that contain non-ascii characters like ö or ü, the game throws an exception when it gets to that point.

UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-4: unexpected end of data

Using character codes like \uC3B6 throws no exception, but I end up with a placeholder box instead of the character I want.

Is there any way to make the function return these characters properly without having access to the remaining code?


Solution

  • Turns out I was using the wrong escape character and the wrong hex codes. And I had to use unicode strings. u'\xF6' and u'\xFC' work perfectly fine for the two characters I was trying to get.