how to write conditionswitch in python

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
User avatar
tacoen
Newbie
Posts: 13
Joined: Fri May 10, 2019 2:48 am
Contact:

how to write conditionswitch in python

#1 Post by tacoen »

how to write renpy conditionswitch in python?

Example:

Code: Select all

    image bg waterfront = ConditionSwitch(
        "time_of_day == 'day'", "waterfront_day.jpg",
        "time_of_day == 'night'", "waterfront_night.jpg",
        )
in python:

Code: Select all

init -1 python:
   cs = ConditionSwitch(
        "time_of_day == 'day'", "waterfront_day.jpg",
        "time_of_day == 'night'", "waterfront_night.jpg",
        )
   time_of_day == 'night'
   renpy.image ("waterfront",cs)
in game:

Code: Select all

	$ time_of_day = 'day'
	scene waterfront
"waterfront_day.jpg" will be shown

debug:

Open your console:

type:

Code: Select all

cs.__dict__['child'].args
Conditionswitch use tuple, so you can do this

Code: Select all

init -1 python:

   ttime = [ 'day','night' ]
   cs = tuple()
   
   for t in ttime:
       cs += ( "time_of_day == '"+t+"'","waterfront_"+t+".jpg" )
       
   renpy.image ("waterfront",ConditionSwitch( *cs ))

Post Reply

Who is online

Users browsing this forum: No registered users