Ren'Py Combining two or more variables to create a new variable.

simarimas

Dev FitB Games
Game Developer
Oct 1, 2018
1,738
3,473
I am just beginning work on a new game. Playing around more than anything. I have searched all over the net, but had no luck in finding the correct answer. Hoping you can help.

I will have multiple variables, which change depending on choices. They could be a girls reactions, or training the MC has done.

So I have say;

$ arialike = a variable number (say 40)
$ ariaflirt = a variable number (say 10)

I want to combine these variables to create a new stat.
$ ariaattracted (arialike + ariaflirt) to equal (50)

I don't want to make game changes to ariaattracted. I want the arialike and ariaflirt used to change ariaattracted. As arialike and ariaflirt will also be used seperately in game.

What code do I use for this?

I have tried multiple different ways, but am having no luck. ariaattracted doesn't change.

Thanks in advance for any help.
 

mimomono

New Member
Feb 6, 2021
9
8
It may not be perfect as I'm not experienced myself but perhaps this could work, I tested it as it is written in the example.

First define/label the variable for ariaattacted like this:
Code:
label item_counter:
$ ariaattracted  = arialike + ariaflirt
return
Then you can just call upon it:
Code:
call item_counter
     if ariaattracted  == 3:
          "arialike and ariaflit are [arialike] plus [ariaflirt] which equals ariaattracted which is [ariaattracted]"
return
 

simarimas

Dev FitB Games
Game Developer
Oct 1, 2018
1,738
3,473
I appreciate it.

Not quite what I was looking for. I don't want to call the stat. I just want it to basically write the sum of ariaflirt and arialike to a completely new stat. That can then be checked against, to see if aria is attracted to the MC.

This way she would be attracted by a combination of the two (or even more) stats instead of just one stat like arialike.

I am hoping to be able to combine several stats to make one. Like also a perv stat, so some girls will be more, or less attracted depending on how big a perv the MC is, in addition to like and flirt.

Thanks for the input.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
My suggestion would be to not have a separate variable.
It's way too easy to forget to recalculate it or fuck it up somewhere by keeping it separate.

If you really must insist on having a variable for it, your original post almost has it already - and using mimomomo's example as the basis...

Python:
default arialike = 0
default ariaflirt = 0

default ariaattracted = 0

# blah, blah, game code...

label middle_of_the_game:

    $ ariaattracted = arialike + ariaflirt
    if ariaattracted >= 30:
        "arialike and ariaflit are [arialike] plus [ariaflirt] which equals ariaattracted which is [ariaattracted]"

# and so the game continues.

But a better way, in my opinion, is to just forget having a 3rd variable...

Python:
    if arialike + ariaflirt >= 30:
        "arialike and ariaflit are [arialike] plus [ariaflirt] which equals ariaattracted which is [ariaattracted]"

That way, it's still easy to read - but removes that extra step of keeping a 3rd variable in line with the other 2.

If you end up doing something more complicated, just use parenthesis (just like math class).

Python:
    if (arialike + ariaflirt  >= 30) or cheating_enabled == True:
        "arialike and ariaflit are [arialike] plus [ariaflirt] which equals ariaattracted which is [ariaattracted]"

if statements are checking if something is True. That something can be as simple as if aria_naked == True: or something more complicated. No matter how complicated the statement becomes, the end result is either True or False and that's all that matters.
 
Last edited:
Apr 24, 2020
192
257
My suggestion would be to not have a separate variable.
It's way too easy to forget to recalculate it or fuck it up somewhere by keeping it separate.
A function could also be used, that way he doesn't have to remember to recalculate it:
Python:
init python:
    def ariaattracted():
        return arialike + ariaflirt
Obviously this gets kinda ugly, since arialike and ariaflirt gets called as is, whereas the third has to be called with ariaattracted().

A solution to this could be to create a class, which might be useful if more characters are to be tracked.
Python:
default aira = CharacterStats()

init python:
    class CharacterStats(object):
        def __init__(self):
            self.like = 0
            self.flirt = 0
        @property
        def attracted(self):
            return self.flirt + self.like
This way aria.like, aria.flirt and aria.attracted all gets called in a similar fashion.

That said, this might be going overboard for a beginner. So using code that is understandable should be a priority.
 

simarimas

Dev FitB Games
Game Developer
Oct 1, 2018
1,738
3,473
Awesome. It worked using the init python ariaattracted()

Thanks so much everyone.