This page is out of date

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.


実行時 init ブロック

init:init python: ブロックの最大の利点は、ゲーム開始のたびに自動的に呼び出されることと、様々なファイルに分散可能なことです。 最も不便な点はinitブロックで作成された変数は、initブロック外で新しい変数に代入しない限り保存されない(そしてロールバックにも参加しない)ことです。 新しい変数に代入したなら、それらは正しく働き、すべての変更は記録されます(たとえstate.love_love_points = a + 1のようにオブジェクト内部の状態であっても)。 以下は例えば00initvars.rpyファイル内に加えられるべきです:

# this file adds a function that sequentially calls
# all __init_variables labels defined in your *.rpy
# files

init python:
    def init_variables():
        initvarlabels = [label for label in renpy.get_all_labels() if label.endswith('__init_variables') ]
        for l in initvarlabels:
            renpy.call_in_new_context(l)  

このファイルを使うには、単にinit_variables関数の呼び出しをstartafter_loadラベルに加えるだけです:

label start:
    $ init_variables()
    # your normal code here

label after_load:
    $ init_variables()
    # your normal code here
    return

initブロックを定義するには、単に__init_variablesラベルをファイル内に作成するだけです(各ファイルと同様に呼び出されるかは心配しなくて良いです。RenPyは自動的に2つ続きのアンダースコアをファイル名に基づいて唯一の接頭辞に置き換えます。) Important: 各変数に対するhasattrの状態を忘れてはいけません。 さもなくば、セーブされた変数はゲーム開始のたびに上書きされます。

label __init_variables:
    python:
        if not hasattr(renpy.store,'a_list'): #important!
            a_list = []
        if not hasattr(renpy.store,'stats_dict'): # important!
            stats_dict = {
                'v':{
                    'lvl':1,
                    'maxhp':4,
                    'hp':3,
                },
                'l':{
                    'lvl':3,
                    'maxhp':6,
                    'hp':5,
                },
            }
    return