[Solved] How to put if conditional statements in action Setvariable?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

[Solved] How to put if conditional statements in action Setvariable?

#1 Post by henvu50 »

How to put if conditional statements in action Setvariable? In what part of the Renpy documentation is this covered?

Setting the variable is the easy part:

Code: Select all

action SetVariable("thatVar", thatVar-1)
But how do you check if a boolean variable is true or false, before incrementing or decrementing a variable using setvariable?

Code: Select all

# i want thatVar to only decrement if someBool == true, but can't figure out the syntax
action SetVariable("thatVar", If(someBool == True, thatVar-1))
Last edited by henvu50 on Mon Jun 21, 2021 4:14 pm, edited 1 time in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: How to put if conditional statements in action Setvariable?

#2 Post by Imperf3kt »

Put the logic in the button, not the action.
Alternatively, you could make the action call a label and then put your conditional statement in there.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: How to put if conditional statements in action Setvariable?

#3 Post by emz911 »

https://www.renpy.org/doc/html/screen_actions.html#If
Something like this?

Code: Select all

If(someBool, true=SetVariable('thatVar', thatVar-1), false=None)
You can replace the None with any other action you want

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: How to put if conditional statements in action Setvariable?

#4 Post by henvu50 »

emz911 wrote: Sun Jun 20, 2021 11:04 pm https://www.renpy.org/doc/html/screen_actions.html#If
Something like this?

Code: Select all

If(someBool, true=SetVariable('thatVar', thatVar-1), false=None)
You can replace the None with any other action you want
Thanks!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]