Page 1 of 1
Only allowing a variable to add to a value the first time an option is clicked?
Posted: Tue Jul 17, 2018 10:41 pm
by NotePaper
The title probably sounds confusing, but i'm not sure how to explain my issue.
I'm creating a dating sim where there is a point system to keep track of the relationship.
Currently the points are added as such:
Code: Select all
menu meetings:
"Who do you want to talk to?"
"Meet Saturn.":
jump saturnmeeting
$ sat_points += 1
"Meet Mercury.":
jump mercurymeeting
$ mer_points += 1
"Meet Mars.":
jump marsmeeting
$ mar_points += 1
"Meet Venus.":
jump venusmeeting
$ ven_points += 1
"Meet Jupiter.":
jump jupitermeeting
$ jup_points += 1
"Meet Neptune.":
jump neptunemeeting
$ nep_points += 1
But, my command returns the user to this menu meetings after each interaction, which means if a user clicks on the same interaction, it will add another point to the system.
How would I make it so it only adds it the first time the interaction happens?
Is that possible or will I need to change the way the introductions work?
Re: Only allowing a variable to add to a value the first time an option is clicked?
Posted: Tue Jul 17, 2018 11:11 pm
by Bellrose980
If you want you could use an if statement so that it will only add a point if the variable equals zero.
Code: Select all
menu meetings:
"Who do you want to talk to?"
"Meet Saturn.":
jump saturnmeeting
if sat_point == 0 :
$ sat_points += 1
"Meet Mercury.":
jump mercurymeeting
if mer_point == 0 :
$ mer_points += 1
"Meet Mars.":
jump marsmeeting
if mar_point == 0 :
$ mar_points += 1
"Meet Venus.":
jump venusmeeting
if ven_point == 0 :
$ ven_points += 1
"Meet Jupiter.":
jump jupitermeeting
if jup_point == 0 :
$jup_points += 1
"Meet Neptune.":
jump neptunemeeting
if nep_point == 0 :
$ nep_points += 1
Hope this helps!!
Re: Only allowing a variable to add to a value the first time an option is clicked?
Posted: Tue Jul 17, 2018 11:26 pm
by MaydohMaydoh
Using set feature of menu, will remove each option from the menu as it's selected so it won't appear next time the menu is shown.
Code: Select all
default meetings_list = []
menu meetings:
set meetings_list
"Who do you want to talk to?"
"Meet Saturn.":
jump saturnmeeting
$ sat_points += 1
"Meet Mercury.":
jump mercurymeeting
$ mer_points += 1
"Meet Mars.":
jump marsmeeting
$ mar_points += 1
"Meet Venus.":
jump venusmeeting
$ ven_points += 1
"Meet Jupiter.":
jump jupitermeeting
$ jup_points += 1
"Meet Neptune.":
jump neptunemeeting
$ nep_points += 1
My guess is you're also using jump to return to the menu after each choice? If so you should place variables before you jump to each label or it won't work.
Code: Select all
"Meet Saturn.":
$ sat_points += 1
jump saturnmeeting
Re: Only allowing a variable to add to a value the first time an option is clicked?
Posted: Wed Jul 18, 2018 12:20 am
by trooper6
Maydoh, where did you find the documentation on the set feature of menu? I couldn't find it anywhere in the Ren'Py documentation and that feature is awesome!
Re: Only allowing a variable to add to a value the first time an option is clicked?
Posted: Wed Jul 18, 2018 1:07 am
by MaydohMaydoh
Can't find any documentation on it, but I saw someone mention it a few days ago in another thread.
Re: Only allowing a variable to add to a value the first time an option is clicked?
Posted: Wed Jul 18, 2018 5:46 am
by xavimat
- Maydoh has pointed it out, but it should be stressed more: You CANNOT put a line after a jump, it will never be executed:
Code: Select all
menu:
"Option1":
jump option1
$ points += 1 # This line won't be executed
- On the other hand, answering your question. I'm not sure if I understand the flow of your game. There are different options:
1. Is it possible in your game to select
more than once the same option in that menu? If not, you can use the solution Maydoh with the "set" feature BUT you need something after the menu when there are no more options. When renpy finds a menu with conditions in a way that there is no option available, it simply skips the entire menu (to avoid blocking the game: a menu without buttons to click!).
2. If the player can click more than once in the same option, and you still want to add one point only the first time, you need
another variable (a flag, or a list) to know that.
Bellrose's solution only works if the variable points is 0 before the menu. But what happens if it isn't? (maybe this menu is in the middle of the game, and there are other parts of the game that have added points already).
This example uses a list (meetings_selected) to keep track of the options already selected. It adds the point only if it's the first time:
Code: Select all
default meetings_selected = []
menu meetings:
"Who do you want to talk to?"
"Meet Saturn.":
if "Saturn" not in meetings_selected:
$ meetings_selected.append("Saturn")
$ sat_points += 1
jump saturnmeeting # remember, this line must be the last one of the block
Re: Only allowing a variable to add to a value the first time an option is clicked?
Posted: Wed Jul 18, 2018 6:09 am
by Remix
trooper6 wrote: ↑Wed Jul 18, 2018 12:20 am
Maydoh, where did you find the documentation on the set feature of menu? I couldn't find it anywhere in the Ren'Py documentation and that feature is awesome!
MaydohMaydoh wrote: ↑Wed Jul 18, 2018 1:07 am
Can't find any documentation on it, but I saw someone mention it a few days ago in another thread.
Might have been me who mentioned it and, like Maydoh I only stumbled onto it from a forum post a good many months ago...
One caveat with it though, if you use the same list for multiple menus keep in mind that the hidden choices are based on the caption, so having the words "Choice 1" in two menus would hide from both. (even that might be useful for some games though, else use different lists)
Re: Only allowing a variable to add to a value the first time an option is clicked?
Posted: Wed Jul 18, 2018 12:07 pm
by Showsni
xavimat wrote: ↑Wed Jul 18, 2018 5:46 am
BUT you need something after the menu when there are no more options. When renpy finds a menu with conditions in a way that there is no option available, it simply skips the entire menu (to avoid blocking the game: a menu without buttons to click!).
Either that, or have one of your menu options run some code that will make its choice (or even another choice) show up in the list again. Something like
Code: Select all
$ girlchoices = ["I think I've talked to everyone."]
label pickgirl:
pass
menu:
set girlchoices
"Talk to Ann":
ann "Hi!"
if len(girlchoices)>2:
$ girlchoices.remove("I think I've talked to everyone.")
"Talk to Beth":
beth "Hello."
if len(girlchoices)>2:
$ girlchoices.remove("I think I've talked to everyone.")
"Talk to yourself":
"You don't have anything to say."
$ girlchoices.remove("Talk to yourself")
"I think I've talked to everyone.":
jump elsewhere
jump pickgirl
Re: Only allowing a variable to add to a value the first time an option is clicked?
Posted: Tue Jul 31, 2018 3:34 am
by phongtinh
If so you should place variables before you jump to each label or it won't work.