How to enable Python 3 mode in Ren'Py 7.4

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
lewishunter
Newbie
Posts: 13
Joined: Sun Aug 01, 2021 8:06 pm
Contact:

How to enable Python 3 mode in Ren'Py 7.4

#1 Post by lewishunter »

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.

Code: Select all

rpy python 3
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

Code: Select all

dictionary.values()[0]
to get the first value of the dict will not work. A solution is doing this for example:

Code: Select all

list(dictionary.values())[0]
For the keys just do:

Code: Select all

 list(dictionary)
Now for the main thing.
In pure Python 2 iterating over a dictionary like this:

Code: Select all

for k, v in dict.items():
    textbutton k action v
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

Code: Select all

for k, v in dict.iteritems():
    ...
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

Post Reply

Who is online

Users browsing this forum: No registered users