Page 1 of 1

Is it possible to put an if else statement into a screen button?

Posted: Thu Apr 07, 2022 3:55 pm
by Michael Regal
Ladies and gentlemen, is it possible to put an if-else statement into a screen button?

I want to translate this into screen language:

Code: Select all

if (d6roll_1_combat + d6roll_2_combat + d6roll_3_combat + brawn_points) >= (d10roll_1_npc + d10roll_2_npc + d10roll_3_npc + 5 - armorvalue):
        $ npchealth -= 1
else:
  $ health -= 1

Re: Is it possible to put an if else statement into a screen button?

Posted: Thu Apr 07, 2022 5:57 pm
by Alex
While you can do it, you'd better put the game logic outside the screen (in a game loop).

Code: Select all

button:
    text "ClickMe!"
    if ...:
        action ...
    else:
        action ...

button:
    text "ClickMe!"
    action If(..., true_action, false_action)

https://www.renpy.org/doc/html/screen_actions.html#If