• To improve security, we will soon start forcing password resets for any account that uses a weak password on the next login. If you have a weak password or a defunct email, please update it now to prevent future disruption.

Ren'Py General flag question

Mescalino

Active Member
Aug 20, 2017
937
6,632
Is this the best way or are there other ways and when would i use what method.
Code:
# check teh concept teh code may be slightly off
Label hot_scene
default HotChick = False
   Boy "Wow that was amazing."
   Girl "Yes that was amazing. Call me again when you want more."

Menu
   Yes:
        Boy "I will do that"
        $ HotChick = True
        jump next_scene
  No:
       boy "i dont think so"
       jump next_scene
Then later in another chapter

Code:
label horney
     boy "I'm Horney"
    
if HotChick:

   boy "I better call that hot chick again"
   Jump HotChick_Scene2
else:
    boy "I better masturbate"
    Jump masterbate_again
Is this the best way or are there better ways?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,202
14,938
There's always better way, whatever the one you choose. Coders are maniacs and generally, if it's not how they would have done it, then it's not the better way.
This said, strictly speaking, you understood how it must be done. But there's better ways...

your code
Code:
if HotChick:
is read as, "if HotChick have a true value". But what's a "true value" ? It's everything except False, None and 0.

The officially correct way:
Code:
if HotChick is True:
which is read as "if HotChick have the value True". And there's only one value True... [suspens] it's : True.

The best officialy correct way :
Code:
if HotChick is False:
    boy "I better masturbate"
    Jump masterbate_again
else:
    boy "I better call that hot chick again"
    Jump HotChick_Scene2
Which is read as, "if the value is still the value by default, then the player haven't done it". Here, "it" mean met the hot chick.

Now, which one you'll choose is up to you.
Both your version and the "best correct" are flexible. By this I mean that, whatever the future of your code, they'll still work as long as you keep False as default value. You want to add a girl, and now HotChick is an integer, a list of name, whatever else ? Your test will still work as intended.

But for me, my last example is still the best because it open one more possibility: the player decide to stick to one girl only.
Now HotChick can become None for to mark that he no longer date random hot chicks. Here, your own code will fail and the player will masturbate because None will be seen as "false-like". This while my last example will still be valid ; it's not False so he'll not masturbate, he'll jump to "HotChick_Scene2".
This mean that, whatever the change you'll make in your game, the change in the code are limited to the strict minimum. Change the value assigned to HotChick when he encounter the first one, and change the code in "HotChick_Scene2", that's all.
Whatever the number of time when you wrote "if HotChick is False:", all these tests will always be valid. If it's still the value by default, then it's the action by default, point. By limiting the number of changes you've to make, you also limit the number of possible bugs.

I'm not sure that I have expressed my thoughts correctly, so, if you want more explanation don't hesitate.
 

Mescalino

Active Member
Aug 20, 2017
937
6,632
Thanks. I will Reverse the statement and use False as given by your explaination it makes more sense.
However the story i am trying to make is fairly linear. There is a startpoint and an end point and it will only have one endpoint. Its kinda the nature of the story. That being said i want to have some side quest to present soem form of diversity.

eg. Will you cheat on your wife. No, well no problem then. Yes, this will open up a new scene where you will beg for forgiveness. Something in those lines. Like Daiting my daughter. Its fairly linear and the goal is clear but it has several sidetracks. Not like I love dady where the story is relatively short but has like a dozen different endings depending on your choices.

Anyaways i dont want to derail my topic. Thanks