if True: Statements

frozenfeet

Well-Known Member
Aug 2, 2019
1,201
1,836
I have a question about the use of "if True:"

I have seen it used in menus like this:
Code:
menu:
    "Yes" if True:
        pass
    "No" if True:
        pass
I have used it myself in some conditional if statements to negate the variable used and it works their as well.

What I am wondering is what is True? Is it just a python default that True is True? So if I used an "if False:" statement would it fail or would it be similar to an "if True:" statement in that False is False?

I've seen this in a few games especially in menus and I really just wonder what is the point of using this condition. And what exactly is the True statement referring to.
 

xj47

Member
Nov 4, 2017
240
399
True and False are the two boolean values (ie. yes/no values) in python and by extension renpy. Say you write the following in renpy:
Python:
$ x = 3
if x > 2:
    "x is greater than 2"
else:
    "x is less than or equal to 2"
When the game reaches the if statement, it evaluates the condition "x > 2" to either True or False and if the result is True it executes the first branch. In this example the condition would always evaluate to False since we are setting the variable immediately before, but in a more complex game variables can have multiple states so the condition can't be pre-evaluated.

You can write something like:

Python:
if False:
    "This line will never show"
But normally there isn't much point. False is always going to be False and so this code branch will never be executed. The reason you might see code like this in practice is usually for debugging. Replacing a variable with a truth constant is a quick way to see how the code would behave if the variable really had that value.

With the example you show, I don't know why someone wrote it like that. As far as I'm aware its the exact same as writing:

Code:
menu:
    "Yes":
        pass
    "No":
        pass
Hopefully this helped
 

Niv-Mizzet the Firemind

Active Member
Mar 15, 2020
571
1,111
They're not written like this.

That happens to me with some games if I use un.rpyc to decompile rpyc files. It just happens for some games, so I think it has to do with the renpy version the game uses. You'll also notice that if statements with an else: are written like this:
Python:
if condition:
    do something
elif True:
    do something else
It doesn't affect the game at all, it's just an artifact of un.rpyc.
 
  • Like
Reactions: frozenfeet

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,585
2,229
I have seen it used in menus like this:
Code:
menu:
    "Yes" if True:
        pass
    "No" if True:
        pass

I somewhat hope you've never seen that exact code... though I can imagine you've seen something similar.

The if statement added to a menu choice makes that the menu choice conditional. That is... the menu choice will only be shown if the evaluated condition results in True.

I'd expect to see something more like:

Code:
menu:
    "Meet Zoe again" if ch02_met_zoe:
        pass

    "Meet Zoe for the first time" if not ch02_met_zoe:
        pass

    "Don't meet Zoe":
        pass

Where the first statement could be if ch02_met_zoe: or if ch02_met_zoe == True: or if ch02_met_zoe is True: or some variation that theme.

In my example, the player would still get a choice between meeting Zoe or not. But the wording would change, based on the value of that variable.

if True: is stoopid. Since True is always True - that choice is no longer conditional and is exactly the same as if the if statement wasn't present. Don't get me wrong... there are a lot of misguided devs out there writing some pretty suspect code - so it may have found it's way into a game. Likewise, as Niv-Mizzet the Firemind says, it could be an odd consequence of how tools like unren or un.rpyc do their job.

Keep in mind, that no matter how complicated or simple, if statements eventually resolve down to something is either True or False. If the stuff after the if evaluates to eventually being True... something happens, otherwise it doesn't.
 
Last edited:

Niv-Mizzet the Firemind

Active Member
Mar 15, 2020
571
1,111
I somewhat hope you've never seen that exact code... though I can imagine you've seen something similar.
If it's a menu that doesn't have conditions for its choices, like the one in the op, un.rpyc will in some games (like insight of you) add an if True in the end, like this (taken from earlier version of insight of you):

Python:
    menu:
        "Enhance!" if True:
            scene fuckfest14a with dissolve
            pause 10
            "..."
        "Continue." if True:
            "..."
If the menu has conditions, it decompiles normally. I agree it's stupid, but from what I can tell it doesn't affect the game.
 

frozenfeet

Well-Known Member
Aug 2, 2019
1,201
1,836
They're not written like this.

That happens to me with some games if I use un.rpyc to decompile rpyc files. It just happens for some games, so I think it has to do with the renpy version the game uses. You'll also notice that if statements with an else: are written like this:
Python:
if condition:
    do something
elif True:
    do something else
It doesn't affect the game at all, it's just an artifact of un.rpyc.
That would explain a lot because I have also seen that "elif True:" as well and I was thinking to my self why doesn't the dev just use an "else:" statement for that instead. And I have used UnRen quite a bit to decompile some games.

Thanks for that answer too, that is a load off my mind not constantly going crazy wondering why some dev kept doing the code that way and what it meant :ROFLMAO: .

You think the ones that do that are from decompiling games that use older versions of Ren'Py? I have noticed that a lot of Ren'Py games still use 7.3.5 but I didn't really pay attention if it was happening to those versions on decompile since I didn't know what the cause was before. But I have played a few games that used Ren'Py versions that were older then 7.3.5 so now I am wondering which versions it happens too :unsure:.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,391
15,305
[...] un.rpyc will in some games (like insight of you)
Too lazy to download it, what's the version of Ren'py used ? It's the third line in the "log.txt" file ; my guess goes for 7.4.7 or perhaps 7.4.8.

It's possible that the rewriting of the core, for the port to Python 3.x, include the inclusion of a forced True value for any entities that can be conditional but don't have a condition. Python good practices say that everything should be explicit, what could lead some devs to using this kind of approach. It could also be due to the new what those parts are handled.

un.rpyc doing a literal translation of the AST, it would then add this "forced True", because it's what the said AST tell it.
 
Apr 24, 2020
192
257
I'm going with the decompiler defaulted to adding an if True: statement.

Another possibility could be that there at one point was something that needed to be checked, but later it got changed and the developer simply changed it to true without thinking more about it.

Worst possibility is that the developer was debugging their code and the real if statement is hiding in a comment nearby. I seem to remember that happening in one of FIFA's decision trees.
 

KiaAzad

Member
Feb 27, 2019
277
207
`if true` and `if False` are usually used as a placeholder for a condition that will be inserted at a later time.