Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Greetings. I've been trying to experiment with Ren'Py 4.7 for the past day to get a better feel for it. Basically, the code that I have for this small script seems sound, but run_game.exe comes up with an error of some sort when it tries to compile the code. The code is reproduced below:
init:
image bedroom = Image("bedroom.jpg")
label start:
scene bedroom
"There's nothing here. How sad."
$ renpy.full_restart()
The script is properly saved as an .rpy file, and the bedroom image is in the same folder as the script. The "run_(folder name)" executable also matches with the folder with the previously mentioned items.
I don't see anything obviously wrong with this. Could you post the error message Ren'Py provides, so that I can use it to figure out what the engine thinks is going wrong?
Last time I had a similar problem with perfectly correct code and crashing (v4.1) was the fact that renpy was extremely sensitive with tab/space characters for indendation. I think what happened was that it wouldn't work if I used spaces instead of tabs for indentation. I'm am not sure if this is still the case but you can check.
I'm sorry, but an exception occured while executing your Ren'Py
script.
LookupError: unknown encoding: unicode_escape
While loading the script.
-- Full Traceback ------------------------------------------------------------
File "run_game.py", line 60, in main
File "renpy\main.pyc", line 149, in main
File "renpy\script.pyc", line 189, in load_script
File "renpy\script.pyc", line 83, in __init__
File "renpy\script.pyc", line 109, in load_file
File "renpy\parser.pyc", line 1188, in parse
File "renpy\parser.pyc", line 145, in list_logical_lines
File "renpy\parser.pyc", line 23, in __init__
LookupError: unknown encoding: unicode_escape
Okay, this is caused by the composition of two problems, one of them yours and one of them mine.
The problem you're having is that you didn't end the file in a newline. Add a couple blank lines to the end of the file, and you'll be fine.
My problem is that I forgot to include an encoding with the exe, which means that you don't see the right error message for that problem. I might cut a 4.7.1 tomorrow fixing this problem, and adding a few new features intended to help the NaNoRenO participants.
Well, adding the newlines didn't fix the problem. Is there a specific number that I need to add? Or perhaps I need to use an escape character instead?
Here's the new error received after adding the newlines:
I'm sorry, but an exception occured while executing your Ren'Py
script.
LookupError: unknown encoding: unicode_escape
While loading the script.
-- Full Traceback ------------------------------------------------------------
File "run_game.py", line 60, in main
File "renpy\main.pyc", line 149, in main
File "renpy\script.pyc", line 189, in load_script
File "renpy\script.pyc", line 83, in __init__
File "renpy\script.pyc", line 109, in load_file
File "renpy\parser.pyc", line 1193, in parse
File "renpy\parser.pyc", line 1171, in parse_block
File "renpy\parser.pyc", line 1117, in parse_statement
File "renpy\parser.pyc", line 1171, in parse_block
File "renpy\parser.pyc", line 1158, in parse_statement
File "renpy\parser.pyc", line 338, in error
File "renpy\parser.pyc", line 23, in __init__
LookupError: unknown encoding: unicode_escape
Oh man, this error fills me up with annoyance and ire just by looking at it... (I had the same problem when I started out... )
Mine was particular about all the lines being exactly four spaces. (Seriously, at one point, I put in five spaces instead of four and it all got snippy at me.) Yours look to be about only three spaces. I suggest you play around with the spacing.
(comes back from experimenting with the sample script)
It's the indenting... it has to be four spaces unless...
A) it's a label. no indentation
B) it's the init block(s) (no indentation for the label, indent 4 spaces afterwards), or
C) you have a branch located in some previous line(s) of "code" (triggered by variable checking or a menu/decision), in which you add another four spaces to the indent unless you are ending the branch. (correct me if I'm wrong here, but would a branch within another branch have a 4+4+4=12 space indent?)
Haha! Thanks for the help, everyone. I've been using tabs to indent the code since 1) it was more convenient than using spaces and 2) it was the convention for indenting code in C++ and Java. Apparently, it failed. Perhaps this could be something that the next version could implement.
Actually, the code does convert tabs to spaces. It assumes an 8-space tab when it does so, so if you have tabs set to something other that 8 spaces, that could definitely cause a problem like this.
(Of course, it doesn't help that the error report is being masked. I'll fix that shortly.)
In general, it's poor programming form to mix tabs and spaces in the same file, especially with indentation-sensitive languages like Python and Ren'Py.