code, howto, Ren'Py

Ren’Py + Python: Part 2: Python Blocks

1_Logo

Working with Ren’Py:

Advanced Ren’Py:

Customizing Ren’Py:

Ren’Py + Python:

Ren’Py is a engine for creating visual novels. It comes with a suite of tools for taking code and transforming it into programs that can be run on Windows, Mac, Linux, and even, with a little more work, mobile platforms like Android and iOS.

Beyond the showing of text and images, Ren’Py can also be extended through introducing new user interface elements, changing its defaults images, and combining Python with its own code to create even more interactive projects.


 

Python Blocks

Beyond the use of the dollar sign for single, one-line statements in Python, Ren’Py also understands arbitrary collections of Python known as blocks.

Ren’Py has two common use cases:

  • init python: Code to define functionality before a project script
  • python: Arbitrary code potentially run during a project script

 

Initializing Python

Screenshot 2018-07-23 12.02.39

Ren’Py understands the use of the keywords “init python” to be the start of Python statements that should be run before any of the Ren’Py code. Used to create functions and other settings, code in init python can be used to prepare for other code.

Ren’Py also expects, although does not enforce, that code placed in in these blocks will not change.

Note:  The use of the define keyword used before the “start” label in Ren’Py is the same as using an init python statement.

 

Python

Arbitrary python code can be placed in a python block. This allows for writing more than single-statement lines with the dollar sign and performing potentially more complex operations.

Screenshot 2018-07-23 12.09.36

As Ren’Py understands Python variables, they can be used directly in python blocks.

 

Example:

Functions can be defined an init python block and then referenced as part of a later python block.

Any variables used in Python or Ren’Py can be intermixed. They used to change their values in a python block and then to show the value to a player as part of Ren’Py dialogue statement.

Screenshot 2018-07-23 12.13.10

Screenshot 2018-07-23 12.15.01

 

GitHub Git Version:

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s