Ren'Py Help with multiple variables

mickydoo

Fudged it again.
Game Developer
Jan 5, 2018
2,446
3,548
Hi all, as per title, I need help making multiple variables. When you visit the girls in my game at night time, I want to assign a number 1 to 5 for the 5 girls, and the game will work off that number the next day for certain scenarios. After a couple of visits each, there could be anything from 3 to 14 points (or whatever ever the fuck it is). I don't want 14 variables to mess about with, I want them in blocks of say 3. If I call the variable visit_points how can I not have to use multiple if satatments.

ie I don't want to do this

if visit_points == 1
if visit_points == 2
if visit_points == 3

Can I do something like this (I've tried it, it don't work)
if visit_points == (1, 2, 3)

I know I can use
if visit_points <= 3
But it will just run me into more problems when I get more points/variables.
 
Last edited:

barotok

New Member
Apr 30, 2019
13
10
Using if or should probably work

eg:

if visit_points==1 or visit_points==2 or visit_points==3:
#do something

if visit_points==4 or #etc...
 
  • Like
Reactions: mickydoo

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,655
23,746
Hi all, as per title, I need help making multiple variables. When you visit the girls in my game at night time, I want to assign a number 1 to 5 for the 5 girls, and the game will work off that number the next day for certain scenarios. After a couple of visits each, there could be anything from 3 to 14 points (or whatever ever the fuck it is). I don't want 14 variables to mess about with, I want them in blocks of say 3. If I call the variable visit_points how can I not have to use multiple if satatments.

ie I don't want to do this

if visit_points == 1
if visit_points == 2
if visit_points == 3

Can I do something like this (I've tried it, it don't work)
if visit_points == (1, 2, 3)

I know I can use
if visit_points <= 3
But it will just run me into more problems when I get more points/variables.
you can check if visit_points is member of a list, tuple or set.
visit_points in [1, 2, 3]​
visit_points in (1, 2, 3)​
visit_points in {1, 2, 3}​
 
  • Like
Reactions: Twistty

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,576
2,203
I guess it comes down to if you want to accumulate points for multiple nights for each girl.

If you're just checking "did I visit girl {X} last night?" the following day, with a single variable... then a list might what you're looking for.

I'm imagining something where you log each visit a single time and then check it later...

Python:
default girls_visited = []

label start:

    "Start:.... "

    scene black

    $ girls_visited = []

    menu pick_girls:
        "Who should I visit now?"

        "Girl 1" if not 1 in girls_visited:
            $ girls_visited.append (1)
            jump pick_girls

        "Girl 2" if not 2 in girls_visited:
            $ girls_visited.append (2)
            jump pick_girls

        "Girl 3" if not 3 in girls_visited:
            $ girls_visited.append (3)
            jump pick_girls

        "Girl 4" if not 4 in girls_visited:
            $ girls_visited.append (4)
            jump pick_girls

        "Girl 5" if not 5 in girls_visited:
            $ girls_visited.append (5)
            jump pick_girls

        "Nobody else":
            pass

    if 1 in girls_visited:
        "I visited girl 1 last night"
    else:
        "I didn't visit girl 1 last night"

    # etc, etc, etc.

    "*** THE END ***"

    return
I'm labeling the menu.
I'm also checking if each girls has already been visited and ignoring her if she has.
Mainly though... for the purpose of your question... I'm using [] as a list, .append to add items to the list and if {item} in {list} to check is something has been added to the list.
$ girls_visited = [] effectively empties/initializes the list.

If you're looking for an accumulation of points across multiple nights... erm... I think you need someone cleverer than I. (is that what tuples might be useful for? with the first element being the lookup for the girl number and a second element being the "accumulated score"?) No clue. I barely understood lists... tuples looked like they needed more reading on my part.

Edit: I've just seen AON's reply. It might be that the .count might be the thing I missing to track multiple visits in a single night (not that my example allows that) or multiple visits across a couple of nights... Since I believe .append will allow the same value to be added to the list lots of times.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,171
I want to assign a number 1 to 5 for the 5 girls, [...] After a couple of visits each, there could be anything from 3 to 14 points (or whatever ever the fuck it is).
[...]
Can I do something like this (I've tried it, it don't work)
if visit_points == (1, 2, 3)
the66 answered the "how", but I'm more concerned by the premise which seem to imply that you'll add 1 to 5 (depending of the girl) to the same variable and this each night.

If it's effectively the case, then it will not works like you expect it. I mean, what 6 will mean the after the second night ? That the player visited the girl 1 and 5 ? That he visited the girl 2 and 4, or that he visited the girl 3 two times ? And obviously, the more night pass, the less understandable will be the value.

You seem to be trying to put a two dimensions array into a single value, which is possible, but not like this, and can't be tested easily anyway.

But what you can still reduce this to a one dimension array :
Code:
default night_visits = []

label whatever:
    menu:
        "visit girl 1":
            $ night_visits.append( 1 )
        "visit girl 2":
            $ night_visits.append( 2 )
        [...]
        "visit girl 5":
            $ night_visits.append( 5 )
        "Go directly to sleep":
            $ night_visits.append( 0 )
Then, you know what girls was visited the night X with this :
Code:
    if night_visits[X] == 1:
        "you visited the girl 1 during the night [X]"
Warning, a list start at index 0, so for the first night, X = 0.

and you know how many time a girl have been visited with this :
Code:
    if night_visits.count( 1 ) >= 3:
        "you visited the girl 1 at least 3 times"
which let you also have things like this :
Code:
label visitGirl2:
    if night_visits.count( 2 ) < night_visits.count( 5 ):
       "Don't lie to me ! I know that you prefer [Girl5], and that you're here only because she's working this night !"
and you can still use intervale :
Code:
    if 2 < night_visit.count( 3 ) < 5:
        "..."
From my point of view, it lead to more simple conditions than all other possible solution.
 
  • Like
Reactions: 79flavors

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,171
(is that what tuples might be useful for? with the first element being the lookup for the girl number and a second element being the "accumulated score"?) No clue. I barely understood lists... tuples looked like they needed more reading on my part.
Tuples are frozen lists. Once you've defined a tuple, it's impossible to add, change or remove a value. So, they are of no use here. See them as multi dimensional constants.
To stay a little on topic, if you want to know what girl was visited and how she was treated, instead of adding the number assigned to the girl in the list, you'll add a tuple :
Code:
label visitGirl1:
    menu:
        "be gentle":
             $ night_visits.append( (1, 0 ) )
        "be rude":
             $ night_visits.append( (1, 1 ) )
Then, when looking at what happen during the night X :
Code:
    if night_visits[X][0] == 1:
        "You visited [girl1] during the night [X]"
    if night_visits[X][1] == 1:
        "You where rude with her"
But, it will also break all I wrote in my previous comment, because the value isn't anymore an integer, but the tuple itself. So, night_visits.count( 1 ) will always return 0.
What is now needed is, nb_visits = night_visits.count( ( 1, 0 ) ) + night_visits.count( ( 1, 1 ) )
 

mickydoo

Fudged it again.
Game Developer
Jan 5, 2018
2,446
3,548
I'm a simple man with simple code. As of now you can go and see the girls, once you have seen one you simply can not see her again until you see the other 4, or I let/make you for some reason. So when you wake up Tuesday morning the variable can only be 1 to 5. Wednesday can only be 3 to 6 etc etc. I let renpy count the variable for me, I can make the game change directions using those numbers, rather than the traditional open the door, peek in the shower, touch your mums tit's route.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,171
I'm a simple man with simple code. As of now you can go and see the girls, once you have seen one you simply can not see her again until you see the other 4, or I let/make you for some reason. So when you wake up Tuesday morning the variable can only be 1 to 5. Wednesday can only be 3 to 6 etc etc. I let renpy count the variable for me, I can make the game change directions using those numbers, rather than the traditional open the door, peek in the shower, touch your mums tit's route.
The issue I pointed stay :
Day 1, go to girl 1, the value is set at 1
Day 2, go to girl 4, the value become 1 + 4 = 5
Day 3... Oh, the value is 5 = 2 + 3, I'll not let the player see the girl 2 and the girl 3, he already did it.

But if it's just to ensure that he'd seen each other girls before going back to a girl, then there's effectively simpler way to do it :
Code:
default visited = []

screen whatever:

    vbox:
        showif not 1 in visited:
            textbutton "go to girl 1":
                action [ AddToSet( visited, 1 ), Jump( "whatever" ) ]

        showif not 2 in visited:
            textbutton "go to girl 2":
                action [ AddToSet( visited, 2 ), Jump( "whatever" ) ]
        [...]
        showif not 5 in visited:
            textbutton "go to girl 5":
                action [ AddToSet( visited, 5 ), Jump( "whatever" ) ]

label newDay:
    # Five row in the list, so five girls visited, reset for the new loop. 
    if len( visited ) == 5:
        $ visited = []
And if you use a menu for the girl selection, then it's even simpler, Ren'py will update visited for you :
Code:
default visited = []

label whatever:
    menu:
        #  Tell ren'py to use /visited/ to store the option already chosen. They'll not
        # be shown again, until they're removed from the list.
        set visited
        "go to girl 1":
            [...]
        "go to girl 2":
            [...]
        "go to girl 5":
            [...]

label newDay:
    # Five row in the list, so five girls visited, reset for the new loop. 
    if len( visited ) == 5:
        $ visited = []