I’m trying to store a dictionary with French letters in it. My line is such:
GameLogic.special_chars={
'French':['Á']
}
When I start the simulation in Blender2.59, I get the error:
SyntaxError: (unicode error) 'utf8' codec can't decode byte 0xc1 in position 0: invalid start byte
Nothing on the script prior to this line is run. It appears that Blender is failing to read the text file, thus not running anything on the script at all.
I’ve found that Blender stores its text files with the encoding CP1252, not UTF8. Could this error be caused by the BGE opening its own internal text files with the wrong encoding, or am I missing an easy Python fix?
Any help/tips appreciated! Thanks!
Dave
-edit-
It’s not obvious in the code snippet so I’ll paste the letter again here: Á (notice the diacritic). Decimal value 193.
-edit2-
Going off the assumption that the problem is with Blender reading internal texts, I’ve created a UTF-8 encoded text file with just ‘Á’ inside it. Blender was successfully able to read it, assign it to a GameLogic variable, and print it.
The problem now is getting it to display on a font map. All characters I’ve tried with accents show up as ‘Ã@’ on screen. The font map does contain the correct characters (Á + others) on it, though I’ll try different ones when I can find them.
Thanks for the reply. I hope it’s not ASCII. It doesn’t have anything like the amount of symbols needed ): Do you know if there is a way to store Á in a CP1252 encoding?
well, i did a simple test file: testaaa.py (ANSI encoding)
print("ÁÀ")
placed in blender addon dir, then tried to import
SyntaxError: Non-UTF-8 code starting with ‘\xc1’ in file C:\Program Files\Blender Foundation\Blender\2.63\scripts\addons estaaa.py on line 1, but no encoding declared;
there was/is and addon for blender-2.6x (dont know if already for .63a…)
to insert special utf-encoding chars for the text-object-string.
Maybe you check the python-code of it to use it for the setting in your game-scripting?
u’unicode’ has been removed for Python 3x. Instead, all strings are stored as unicode when defined like “string”. You can store ‘Á’ as bytes, but you can’t assign that to a Text object.
@CoDEmanX: It’s not Python I’m having issues with. I can manipulate and store the strings, but displaying them in Blender has been difficult. I haven’t yet figured out what format the Text objects are. The error messages tell you what you can’t do, rather than what it’s expecting.
I have made some progress solving this! You can import a text file with UTF-8 encoding into a Blender Text object using the ‘Paste File’ feature. The default Blender font doesn’t have the right characters so you’ll need to change it to something else to see your efforts in the BGE. So far I haven’t been successful assigning text to the Text object using Python, but I’ll keep trying.