Ren’Py Basic

Download

https://www.renpy.org/latest.html

Documentation

https://www.renpy.org/doc/html/

Python Basic

  • integer: 42
  • float: .5, 7., 9.0
  • string: "Hello", 'World'
  • boolean: True, False, None
  • tuple: (42, "Hello")
  • list: [1, 2, 3, 4]
  • variable: name, isNight
  • field: config.screen_width
  • call: e = Character("Eileen", type=adv, color="#0f0")

Ren'Py Basic

Image Name

Two part: {image name} [{image tag}]
e.g. monika happy night

Simple Expression

i.e. Python expression

At List

​​show monika at t11, w31

Label

1. local & globallocal

local: label .local_label
global: label global_label

2. block

label .block1:
    "This is block1."
label .block2:
    "This is block2."

3. jump

label .loop_start:
    e "Infinite loop"
    jump .loop_start

4. call

call subroutine
call subroutine(100)
call expression "subroutine" pass (count=3)

label subroutine(count=1):
    e "I get here [count] times!"
    return

5. Ren'Py label

  • start: Game start jump to.
  • quit: game exit jump to.
  • after_load: after load slot.
  • splashscreen: first game start (before menu).
  • before_main_menu: before menu.
  • main_menu: (if not use default) when return, go to start label.
  • after_warp: call this when use wrap.

Dev Tools

Most tools require config.developer = True

Shift + o: Console (when config.console = True)
Shift + e: Open Text Editor
Shift + d: Open Dev Menu
Shift + r: Reload
Shift + i: GUI inspecting
Shift + y: Styles backup
>: Fast skip

--warp: renpy.exe project --warp script.rpy:420
renpy.get_filename_line()
renpy.log(msg)
renpy.unwatch(expr)
renpy.watch(expr)

Dialogue & Narration

Say

  • { }: tag
  • [ ]: substitution

Define Character

define e = Character("eileen", who_color="#c8ffc8")

Character(name, kind=adv, **args)

  • name
  • kind
  • image
  • voice_tag
  • what_prefix
  • what_suffix
  • who_prefix
  • who_suffix
  • dynamic: boolean
  • condition
  • interact
  • advance
  • mode
  • callback
  • ctc
  • ctc_pause
  • ctc_timedpause
  • ctc_position
  • screen
  • show_layer

config.say_attribute_transition: 设置图片改变转场

# extend
show eileen
e "Sometimes, I feel sad."
show eileen happy
extend " But I usually quickly get over it.

Window

window show
window hide

window show dissolve
window hide dissolve

# show window when pause, hiden before scene change
window auto 

_window
_window_auto
_window_show(trans=False)
_window_hide(trans=False)

Image

  • image: define new image
  • show: show image on lyaer
  • scene: remove all layer
  • hide: hide select image

folder

JPG or PNG
images folder & sub-foler
game/images/eileen happy.png

define

image eileen happy = "eileen_happy.png"
image black = "#000"
image bg tiled = LiveTile("tile.jpg")

show

  • as: alias
  • at: (default) transform
  • behind: tag
  • onlayer
  • zorder: z value

hide

  • onlayer

with

with None
with dissovle

image function

renpy.can_show(name, layer=None, tag= None)
renpy.check_image_attributes(tag, attributes)
renpy.copy_images(old, new): renpy.copy_images("eileen", "eillen2")
renpy.get_attributes(tag, layer=None)
renpy.get_ordered_image_attributes(tag, attributes=(), sort=None)
renpy.get_placement(d)
renpy.get_say_image_tag()
* renpy.get_showing_tags(layer='master')
renpy.has_image(name, exact=False)
renpy.seen_image(name)
renpy.showing(name, layer='master')
renpy.start_predict(*args)
renpy.stop_predict(*args)

Menu (Branch)

menu:
    "我应该?"
    "喝咖啡":
        "我喝了咖啡,每一口都非常棒。"
    "喝茶":
        $ drank_tea = True
        "我喝了茶,并努力使讲话不像发表政治声明。"
    "自杀":
        "我死了。"
        return
    
label after_menu:
    "喝完饮料后,开始继续我的晨间时光。"
    
menu:
    "向左看":
        "墙!"
    "向右看":
        "墙!"
    "向前看" if drank_tea:
        "墙!"

Python Statements

block style

python:
    flat = True

line style

$ flag = True
$ remance_points = 0
$ romance_points += 1
$ renpy.movie_cutscene(opening.ogv")

init

init (priority) python call when game init. Define class and function here. Assign priority (from 0 to 500 best). Call from low to high.

init 1 python:
    # unlock bad end
    persistent.endings.add("bad_ending")

default

default points = 0
default schedule.day = 0

init offset

set priorite
init offset = 1

store

init python in mystore:
    def serial():
        …

init python:
    import store.mystore as mystore
    
label start:
    $ serial = mystore.serial()

package

official package: /game
thired party package (pure python): /game/python-packages

pip install --target game/python-packages requests

warning: No rollback support for .py import object

Condition

if

if flag:
    …
elif otherFlag:
    …
else
    pass

while

$ count = 10
while count > 10:
    "[count] times."
    $ count -= 1
"Start!"    
No continue, break and for

pass

pass do nothing but full-fill the block

Audio

support audio format:

  • OPUS
  • OGG Vorbis
  • MP3
  • WAV (PCM)

default 3 audio track:

  • music
  • sound
  • voice

use renpy.music.register_channel() create new track (channel)

audio channel support current audio play

play

play music "mozert.ogg
play sound "woof.mp3"
play myChannel "punch.wav" # register it first 

play music ["a.ogg", "b.ogg"] fadeout 1.0 fadein 1.0
play audio "sfx1.opus"
play audio "sfx2.opus"

stop

stop music [fadeout 1.0]

queue

queue music ["a.ogg", "b.ogg"] [loop/noloop]

partial playback

play music "<from 5 to 15.5>waves.opus"
play music "<loop 6.333>song.opus"

silence

play audio ["<silence .5>", "boom.opus"]

namespace

define audio.sunflower = "music/sun-flower-slow-jam.ogg"
play music sunflower

audio function

renply.play(filename, channel=None, **kwargs)
renpy.seen_audio(filename)
renpy.music.get_duration(channel='music')
renpy.music.get_pause(channel='music')
renpy.music.get_playing(channel='music')
renpy.music.get_pos(channel='music')
renpy.music.is_playing(channel='music')
renpy.music.play(filenames, channel='music', loop=None, fadeout=None, synchro_start=False, fadein=0, tight=None, if_changed=False)
* renpy.music.register_channel(name, mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True, movie=False)
renpy.music.set_pan(pan, delay, channel='music')
renpy.music.set_pause(value, channel='music')
renpy.music.set_queue_empty_callback(callback, channel='music'')
renpy.music.set_volumn(volume, delay=0, channel='music')
renpy.music.stop(channel='music', fadeout=None)

sound function

same to music function.
use renpy.sound.

movie

use llbav coder.

  • VP9
  • VP8
  • Theora
  • MPEG 4 part 2 (Xvid & DivX include)
  • MPEG 2
  • MPEG 1

  • WebM

  • Matroska

  • Ogg

  • Avi

  • Various kinds of MPEG stream

playback movie

$ renpy.movie_cutscene("movie.webm")

Voice

voice "line0001.ogg"
"Welcome"

voice sustain
"… to ren'py"

sustain guarantee voice not stop when user interact

voice tag

define e = Character("Eileen", voice_tag="eileen")
define l = Character("Lucy", voice_tag="lucy")

screen voice_toggle:
    vbox:
        textbutton "Mute eileen" action ToggleVoiceMute("eileen")
        textbutton "Mute lucy" action ToggleVoiceMute("lucy")
        
label start:
    show screen voice_toggle
    
    voice "e01.ogg"
    e "Mute me"
    
    voice "l01.ogg"
    l "shut up!"
    
    voice "l02.ogg"
    l "Not me!!!"

auto voice

config.auto_voice = "voice/{id}.ogg"
id is show in extract dialogue table.

voice function

_get_voice_info()
voice(filename, tag=None)
voice_can_replay()
voice_replay()
voice_sustain(ignored=u'', **kwargs)

voice actions

PlayCharacterVoice(voice_tag, sample, selected=False)
SetCharacterVolume(voice_tag, volume=None)
SetVoiceMute(voice_tag, mute)
ToggleVoiceMute(voice_tag, invert=False)
VoiceReplay(*args, **kwargs)