This plugin allows you to offer timed choices in a Ren'Py project, where something happens if the player takes too long to select an option. It introduces a new command that integrates seamlessly in the Ren'Py scripting language.
- Create a
_pluginsfolder inside your project'sgamefolder. NOTE: the naming of this folder is important becquse of the loading order of files in Ren'Py (sее documentation). - Extract the files to your project's
game/_plugins/timedchoicefolder (or clone this repository insidegame/_plugins). - You can test that the plugin works properly by including the following in your
game/script.rpyfile:
label start:
call plugin_timedchoice_demoThis will launch a demo script that explains the capabilities of the plugin next time you launch your game.
The demo folder from this plugin can be removed afterwards, as it only serves to showcase its capabilities, and is not essential for it to work peroperly.
You can adjust how the visual indicator looks by tweaking the following properties in engine/timedchoice.rpy:
# The color of the bar background (when it's empty).
define gui.timedchoice_bar_bg_color = gui.muted_color
# The color of the bar fill (when it's full).
define gui.timedchoice_bar_fill_color = gui.accent_color
# The width of the timer bar in pixels.
define gui.timedchoice_bar_width = gui.choice_button_width / 2
# The height of the timer bar in pixels.
define gui.timedchoice_bar_height = 10You can adjust the default timer by tweaking the following property in engine/timedchoice.rpy:
# The default time for timed choices in seconds.
define default_timer = 3.0You can allow the user to adjust the speed of timed choices by adding the following code in the preferences screen in your screens.rpy file:
screen preferences():
# Add the following after the "Text Speed" slider
label _("Timed Choice Speed")
bar value VariableValue("persistent.timedchoice_speed", min=0.5, max=2.0, step=0.25, force_step=True, style="slider")You can adjust the values in the VariableValue constructor:
minis the lowest possible speed;maxis the highest possible speed;stepis the speed difference between each step of the slider.
Using the settings provided in the example, you would end up with a slider that allows the user to select: 0.5, 0.75, 1.0, 1.25, 1.5, 1.75 and 2.0.
This speed parameter represents how much faster the timer elapses. For example, using a timer of 3s:
- A speed of 0.5 will make the choice last 6 seconds (twice slower);
- A speed of 1.0 will make the choice last 3 seconds;
- A speed of 2.0 will make the choice last 1.5 seconds (twice faster).
The following examples are meant for technical reference. Please refer to the demo for more concrete examples that show how the plugin may be useful gamewise.
The syntax of the new timedchoice command mimicks that of the built-in menu command.
Rules:
- The
timedchoicecommand must be followed by:and a new block. - Each option must be a
string(arbitrary text marked by double quotes"), must be followed by:and a new block. - The block of commands for each option can be any valid block in the Ren'Py syntax.
Example:
timedchoice:
"Option 1":
# What to do when option 1 is selected
"Option 2":
# What to do when option 2 is selected
"Option 3":
# What to do when option 3 is selectedThis will prompt the user to take a pick between all 3 options and execute only the block of commands associated with that option. If the choice times out (the user hasn't selected any options before the timer runs out), then nothing happens.
It is possible to force an option to be picked when the choice times out. To do this, add a timeout keyword before the option's name.
Rules:
- The
timeoutkeyword may be included, and must be written before the option's name. - A single choice must not have more than 1
timeoutoption.
Example:
timedchoice:
"Option 1":
# What to do when option 1 is selected
"Option 2":
# What to do when option 2 is selected
timeout "Option 3":
# What to do when option 3 is selectedThis will behave like the previous example, except that if the choice times out (the user hasn't selected any options before the timer runs out), the block define after "Option 3" will be executed.
NOTE: a transform will be applied to the default option that allows to visually identify it. This transform is labeled as timedchoice_default_option and can be overriden to suit your needs.
Example:
transform timedchoice_default_option:
# This transform does not modify the base display,
# thus rendering the default choice indistinguishable
# from the others.
matrixcolor IdentityMatrix()It is possible to define a time-out option that cannot be picked manually, and thus is triggered only on time-out.
Rules:
- The
hidetimeoutparameter may be included in thetimedchoicecommand block. - If it is present, the
hidetimeoutparamter must be followed by an expression. - The expression following the
hidetimeoutparameter must resolve to a bool (TrueorFalse).
Example:
timedchoice:
hidetimeout True
"Option 1":
# What to do when option 1 is selected
"Option 2":
# What to do when option 2 is selected
timeout:
# What to do when option 3 is selectedThis will behave like the previous example, except that the third option will not be listed in the options that the user can pick.
NOTE: though it is technically possible to give a caption to the hidden option, like for any other options, it doesn't really make any sense since the option will not be displayed anyway. However, you may want to give it a caption anyway, in the case the hidetimeout option is variable.
Example:
init python:
def somelogic():
# Write some logic that returns True or False
timedchoice:
# Whether the time-out option is hidden will be decided according to the result of the somelogic() function
hidetimeout somelogic()
"Option 1":
# What to do when option 1 is selected
"Option 2":
# What to do when option 2 is selected
timeout "Option 3":
# What to do when option 3 is selectedIt is possible to modify the time allocated to the user to make his decision.
Rules:
- The
timerparameter may be included in thetimedchoicecommand block. - If it is present, the
timerparamter must be followed by an expression. - The expression following the
timerparameter must resolve to a number.
Example:
timedchoice:
timer 10
"Option 1":
# What to do when option 1 is selected
"Option 2":
# What to do when option 2 is selected
timeout "Option 3":
# What to do when option 3 is selectedThis will behave like the previous example, except that the user will have 10 seconds instead of the default 3 to think and make a choice.
NOTE: just like the hidetimeout paramter, the timer parameter can be set using a variable or a function.
Example:
timedchoice:
# This will cause the timer to be set to a random number between 2 and 5
timer renpy.random.randint(2, 5)
"Option 1":
# What to do when option 1 is selected
"Option 2":
# What to do when option 2 is selected
timeout "Option 3":
# What to do when option 3 is selected