How to enable Python 3 mode in Ren'Py 7.4
Posted: Fri Jan 07, 2022 2:36 am
As Ren'Py 8 (Python 3) is kinda already a thing, at least in the nightlies (test versions basically), I think that some users may want to start porting their current projects. I know this is old news (since 7.4.0) but I know that getting all the info is difficult for a newbie. So i am gonna make it painfully simple.
Just add this line at the beginning (1st line) of each .rpy file you have.
That's it, very simple... and It took me a lot to figure out. If for some reason it does not work, click the 'Force Recompile' button on the launcher.
Now, what happens next... Let Tom explain it to you:
https://www.renpy.org/doc/html/changelo ... ility-mode
But in summary, divisions are not rounded (this is the main issue for simple games) and when you use the dictionary methods .keys(), .values() and .items() will not convert the dict into a list and you have to do it yourself if needed. It's fine just for iterating, but if you want to do this to get the first value of the dict will not work. A solution is doing this for example:
For the keys just do:
Now for the main thing.
In pure Python 2 iterating over a dictionary like this:
Is inefficient because it has to convert the dictionary into a list (redundant).
But the Python 2 efficient way to do it is not supported in Python 3
Enabling Python 3 compatibility let's you use .items() in a efficient way.
For more info visit: https://www.renpy.org/doc/html/implemen ... three.html
However, this is NOT PYTHON 3, just a taste of it. If you want ordered dictionaries, f strings, and the juicy data classes you will have to wait for Ren'Py 8
Just add this line at the beginning (1st line) of each .rpy file you have.
Code: Select all
rpy python 3Now, what happens next... Let Tom explain it to you:
https://www.renpy.org/doc/html/changelo ... ility-mode
But in summary, divisions are not rounded (this is the main issue for simple games) and when you use the dictionary methods .keys(), .values() and .items() will not convert the dict into a list and you have to do it yourself if needed. It's fine just for iterating, but if you want to do this
Code: Select all
dictionary.values()[0]Code: Select all
list(dictionary.values())[0]Code: Select all
list(dictionary)In pure Python 2 iterating over a dictionary like this:
Code: Select all
for k, v in dict.items():
textbutton k action vBut the Python 2 efficient way to do it is not supported in Python 3
Code: Select all
for k, v in dict.iteritems():
...For more info visit: https://www.renpy.org/doc/html/implemen ... three.html
However, this is NOT PYTHON 3, just a taste of it. If you want ordered dictionaries, f strings, and the juicy data classes you will have to wait for Ren'Py 8