Ren'Py Learning Renpy. Need some help!

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,845
24,499
I'm here again :)

Let's say I have a lot of vars.

Code:
a = false
b = false
c = false
d = false
...
n = false
Through dialog I may change them or may not. I have a route where they weren't changed, so how could I code the condition like

Code:
if a == false and b == false and c == false .... :
jump
I know I can't use so many "ands".
Python:
if not True in [a, b, c, ..., n]:
    jump somewhere
or
Python:
if not (a or b or c or ... n):
    jump somewhere
When I press CTRL it skippes/forwardes?
it is actually <SHIFT> + <R>
 
Last edited:

PandaLulz

Assets Grabber
Uploader
Aug 18, 2017
1,262
7,472
Python:
if not True in [a, b, c, ..., n]:
    jump somewhere
or
Python:
if not (a or b or c or ... n):
    jump somewhere
it is actually <SHIFT> + <R>
Thank you for this, branching dialogue is hurting my brain.
 

Higurashika

Well-Known Member
Nov 15, 2018
1,410
2,015
Hi again. I just wanted to ask how to do fixes properly? Fix script file and build distribution again? Or I can use original script.rpy file?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,129
16,620
Hello. Can I use ConditionSwitch for characters?
Hmm, what do you mean exactly ?
If you struggle to explain it, write the code you have in mind as if it worked, it should already give a good idea of what you try to achieve.
 

Higurashika

Well-Known Member
Nov 15, 2018
1,410
2,015
Hmm, what do you mean exactly ?
Well, my whole idea was to switch characters depending on the value of the variable. I mean, mc has a spouse who can be a guy or a girl. And when spouse talks renpy should show not only the name (which is easily done), but different color for names (at least).
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,129
16,620
Well, my whole idea was to switch characters depending on the value of the variable. I mean, mc has a spouse who can be a guy or a girl. And when spouse talks renpy should show not only the name (which is easily done), but different color for names (at least).
Well, so no, you can't use ConditionSwitch for something like that. It's a displayable, basically speaking it's designed to draw something on the screen.

But it's not really difficult to have your own equivalent, usable for more generic values.
/!\ I wrote it on the fly, but normally it should works /!\
Python:
init python:

    class ConditionValue( renpy.python.RevertableObject ):
        def __init__( self, variable, default, *args ):
            '''
                ConditionSwitch-like object.

                - variable [String]
                     Name of the variable (should be scalar-like and not an object attribute)
                    that will be used to test the condition.

                - default [whatever]
                     Value to return by default. Either because the variable do not exist yet,
                    or because its value match none of the defined conditions.

                - As many tuples ( "condition value", "returned value" ) as you want.
                     The "condition value" is the expected value for the variable, while the
                    "returned value" will be what the object return if the condition match.
            '''
            self.variable = variable
            self.default = default
            self.conditions = args

        def __call__( self ):
            #  If the variable do NOT exist, return the value defined
            # as default.
            if not hasattr( store, self.variable ):
                return self.default
            # Get the current value
            value = getattr( store, self.variable )
            # Test all the defined values
            for v, rv in self.conditions:
                # If the "condition value" correspond, return the associed
                # "value to use".
                if value == v:
                    return rv

            #  The value correspond to none of the "condition value",
            # therefore, return the default value.
            return self.default


define mcSpouseGender = "Female"
#  The color for the name (/who_color/) will be based on the
# /mcSpouseGender/ variable. By default the color is white (/#FFF/).
# But if the variable value is "Female", the color will be pinkish (/#FF80FF/)
# and if the variable value is "Male", it will be blue (/#00F/).
define mcSpouse = Character( "[mcSpouseName]", who_color=ConditionValue( "mcSpouseGender", "#FFF", ( "Female", "#FF80FF" ), ( "Male", "#00F" ) ) )
default mcSpouseName = "Alice"

label whatever:
    menu:
        "What is the gender of your spouse ?"
        "Female":
            $ mcSpouseGender = "Female"
        "Male":
            $ mcSpouseGender = "Male"
 
Last edited:
  • Like
Reactions: Higurashika

Higurashika

Well-Known Member
Nov 15, 2018
1,410
2,015
For some reson it asks to check strings and parenthesis in
define mcSpouse = Character( "[mcSpouseName]", who_color=ConditionValue( "mcSpouseGender", "#FFF", ( "Female", "#FF80FF" ), ( "Male", "#00F" ) )

ah, okay, this stroke needs another " )"
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,129
16,620
ah, okay, this stroke needs another " )"
Oops, sorry. I edited my comment to fix this.


Okay, now i've got "not a color" error.
Hmm. Yeah, in a way it's normal, since it's effectively not a color error... I thought it would works, but apparently Ren'py don't validate when I expected it to do it.

I'll think about that and try to find a better solution. In between, there's always the "hard coded" solution:
Python:
# Need to be saved in order to keep the change.
default mcSpouse = Character( "[mcSpouseName]" )
default mcSpouseName = "Alice"

label whatever:
    menu:
        "What is the gender of your spouse ?"
        "Female":
            $ mcSpouse.who_args["color"] = "#FF80FF"
        "Male":
            $ mcSpouse.who_args["color"] = "#00F"
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,129
16,620
This is so beyond my level, that I barely understand your code :) Thank you, now it works!
It's just an overwrite of what Ren'py naturally do.

You can pass a lot of arguments/parameters when you create a character, among them you can customize the way the name is displayed, and the way the dialog is displayed. By example, Character( "name", who_color="#F00", what_size=12 ) would display the name in red, and the dialog with a letter size of 12 (probably way too small).
In order to not over complicate the storage, Ren'py will split the arguments in two, using the underscore as separator. Then it will store all the "who" in a dictionary, and all the "what" in another ; what led to my initial error, wrongly using "who" as name for the dictionary.

The hard coded solution is just to find where Ren'py store the value, and to change it.
The only pitfall is to use default when creating the character object, else it will not be saved, and the change will not be propagated from a play to another.
 

Higurashika

Well-Known Member
Nov 15, 2018
1,410
2,015
Another stupid question.

I have a weight = 60. How to lock this number for decreasing? I've found a code, but I don't undestand how it should work.

define limiter_for_x():
global x
x= max(x, 60)

config.python_callbacks.append(limiter_for_x)


upd

Okay, I'm not that stupid and managed to apply this code after all, yay!
 
Last edited: