You've reached a page on the Ren'Py wiki. Due to massive spam, the wiki hasn't been updated in over 5 years, and much of the information here is very out of date. We've kept it because some of it is of historic interest, but all the information relevant to modern versions of Ren'Py has been moved elsewhere.
Some places to look are:
Please do not create new links to this page.
This code creates console screen that can process any python input put in it. Thus it can be useful as developer tool or if you are doing more demanding games, it is useful to do instant debugging and modification of game state.
This code requires code and codeop module from standard python (included in the zip).
init -998 python:
import code, sys # requires code module, which is not provided in renpy
class Console(code.InteractiveConsole):
"""console class
Shows developer console by pressing ";"
This console is normal python interpreter, thus it can modify anything in the game.
Use with care.
"""
MAX = 20
""" maximum lines to display. Change if you have higher resolution"""
MAX_LINE = 60
""" maximum characters per line. Change if you have higher resolution """
def __init__(self, *args, **kwargs):
code.InteractiveConsole.__init__(self)
self._history = [] # history is stored here
for x in xrange(Console.MAX):
self._history.append("")
self._cont = False
def show_console(self):
renpy.call_in_new_context("_console")
def hide_console(self):
return False
def execute(self, stmt):
stmt = stmt.replace(">>> ", "").replace("... ", "").rstrip("\n\r\t ")
self._history.append(stmt)
if len(self._history) > Console.MAX:
self._history.pop(0)
sys.stdout = self
self._cont = self.push(stmt)
sys.stdout = sys.__stdout__
def write(self, data):
dlines = data.split("\n")
nlines = []
for l in dlines:
while len(l) > Console.MAX_LINE:
nlines.append(l[:Console.MAX_LINE])
l = l[Console.MAX_LINE:]
nlines.append(l)
for l in nlines:
if l.strip("\nrt ") == "":
continue
self._history.append(l.strip("\n\r\t"))
if len(self._history) > Console.MAX:
self._history.pop(0)
store.console = Console()
def start_callback():
renpy.show_screen("console_manager")
config.start_callbacks.append(start_callback)
screen console:
zorder 101
modal True
window:
vbox:
area (10, 10, 790, 500)
for cmd in store.console._history:
text "[cmd!q]" size 20
vbox:
area (10, 510, 790, 590)
if store.console._cont:
input default "... "
else:
input default ">>> "
key "K_BACKQUOTE" action store.console.hide_console
screen console_manager:
zorder 100
key "K_BACKQUOTE" action store.console.show_console
label _console:
show screen console
$ cmd = ui.interact()
if cmd is not False:
$ console.execute(cmd)
hide screen console
jump _console
return
Load the module by using renpy.load_module Just press ~/backquote character to open console in new context. To get away from the console, just press ~/backquote again.