Ren'Py Sandbox map

Lilou_5

New Member
May 4, 2020
10
2
3
Do I have to use only "If" and "True/False" for event control?
Or is there anything else I need to do?
And if a location has more than 10 events, can I still do it with "if"?

And how to avoid the events interfering with each other?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
12,759
20,981
1,026
Do I have to use only "If" and "True/False" for event control?
Mostly yes for the if. As for the True/False, it's tricky.
In a way, a condition is always summarized to True/False, in this way that, when you write something like :
Code:
if thisVariable == 5 and thatOne == "blue":
   [Do something]
else:
   [do other thing]
In a "human language" it mean :
Do something if it's true that thisVariable is equal to 5 and thatOne is equal to "blue"
but do other thing if it's false that ...
But as you can see, the True/False are here implicit and the condition itself is more complicated.

[note: Here I'll use label for the example, because it's easier to understand. But the same logic apply to if inside a screen]

You can also have the condition somewhere else :
Python:
init python:
    def aCondition():
        # The first condition isn't met, so it can't be True.
        if thisVariable != 5: return False
        # The first condition is met, but not the second,
        # so it still isn't True.
        if thatOne != "blue": return False
        # The two conditions are met, so it's True.
        return True

label whatever:
    if aCondition():
   [Do something]
else:
   [do other thing]
In this particular case, it's a little useless, but it can be interesting when the same condition scheme is used a lot.

Let's say that you have three characters, and that your game rely on action did, or not, depending of the "love level" of those characters. Your conditions for this will looks like :
if annieLove >= 5:
if sophieLove >= 12:
if maryLove >= 1:

You can simplify this by using a function to test the condition :
Python:
init python:
    def loveCondition( girl, limit )
        # Python let you address a variable "anonymously".
        # You don't know its name when you write the code, just its
        # syntax : "name of the girl" + "Love".
        # Here you get the love level for the right girl.
        testValue = getattr( store, girl + "Love" )
        # And here you test its value in regard of the gave limit.
        if testValue >= limit: return True
        # The test failed, so the condition isn't met.
        return False

label annieBedroom:
    "You enter her room."
    if loveCondition( "annie", 5 ):
       "Annie looks pleased to see you."
    mc "How are you today ?"
    [...]

label sophieBedroom:
    "You enter her room."
    if loveCondition( "sophie", 15 ):
       "Before you can say a word, Sophie kiss you."
       mc "Wow, I really love your greetings."
    mc "How are you today ?"
    [...]
Once again, I kept the condition simple, and in this particular case there's few to gain working this way.
But it become interesting if you've a condition more complex, like :
Code:
if sophieLove >= 15 and sophieAngry == False and mcIsMonogamous == True:
which would looks like:
Python:
init python:
    def loveCondition( girl, limit )
        # The first condition isn't met.
        if not getattr( store, girl + "Love" ) >= limit: return False 
        # The second condition isn't met.
        if getattr( store, girl + "Angry" ) == True: return False
        # The third condition isn't met.
        if mcIsMonogamous == False: return False
        return True

label whatever:
    if loveCondition( "sophie", 15 ):
       [do something]
The more complex the condition is, the more you risk to make an error when writing it. Therefore, the more you'll gain to use a deported condition, because there's less to write.


Or is there anything else I need to do?
And if a location has more than 10 events, can I still do it with "if"?
That you need to do, no. That you can do, yes ; and it answer the following question.

Depending of the way you define your map, there's two way to decide if a button is usable or not.

Using if to condition the display of the button :
Code:
screen whatever():
    if condition == True:
        imagebutton:
          idle "my button.png"
          action [...]
If the condition is True, the button will be shown, and the player will have the possibility to click on it.

Using the sensitive property of buttons :
Code:
screen whatever():
    imagebutton:
      idle "my button.png"
      sensitive condition == True
      action [...]
Here, the button will always be seen, but it will be clickable only if the condition is True.
You can have a better and more intuitive result with this method is you also use the "insensitive" property :
Code:
screen whatever():
    imagebutton:
      idle "button when clickable.png"
      insensitive "button when not clickable.png"
      sensitive condition == True
      action [...]

And how to avoid the events interfering with each other?
By being very careful. It's, alas, the only way.
You can use if/elif/else to limit the risk :
Python:
if annieLove < 4:
   [do nothing]
elif annieLove < 10:
   [do something]
elif annieLove < 15:
   [do another thing]
else:
   [yet something else]
But in the end, when the conditions start to be more complex, only an attention to the details will prevent events to interfere with each others.