Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
-
Mimic Fox
- Newbie
- Posts: 13
- Joined: Wed Aug 05, 2020 8:52 pm
-
Contact:
#1
Post
by Mimic Fox » Thu Aug 06, 2020 12:53 am
I'm currently making a mystery visual novel. At the end of each case the player will have to answer several questions in a row to come to a conclusion on what happened. Here's a simple example of how I'm doing these bits right now.
Code: Select all
$ correct_answer_points = 0
menu:
"What was the murder weapon?"
"Scissors":
$ correct_answer_points += 0
jump question2
"Gun":
$ correct_answer_points += 0
jump question2
"Knife":
$ correct_answer_points += 1
jump question2
label question2:
menu:
"Who was the Murderer?"
"Nozomi":
$ correct_answer_points += 0
jump final
"Maki":
$ correct_answer_points += 1
jump final
"Chika":
$ correct_answer_points += 0
jump final
label final:
if correct_answer_points == 2:
"That's right!"
else:
"That's wrong!"
Is this a good way to do it? Is there a better/simpler way?
-
IrinaLazareva
- Veteran
- Posts: 399
- Joined: Wed Jun 08, 2016 1:49 pm
- Projects: Legacy
- Organization: SunShI
- Location: St.Petersburg, Russia
-
Contact:
#2
Post
by IrinaLazareva » Thu Aug 06, 2020 9:36 am
Are you looking for a
simpler solution or a more
optimized one? I suppose your code is simple enough and does not require simplification.
There is a golden rule, if the code works, it's better not to touch it.
If it's about optimization. Then yes, there are ways.
For example, a
menu statement already has
a label. That is, the code:
can be replaced:
https://www.renpy.org/doc/html/menus.html#in-game-menus
And
jump is unnecessary. The code:
Code: Select all
menu:
"What was the murder weapon?"
"Scissors":
$ correct_answer_points += 0
jump question2
"Gun":
$ correct_answer_points += 0
jump question2
"Knife":
$ correct_answer_points += 1
jump question2
label question2:
menu:
"Who was the Murderer?"
is equivalent to:
Code: Select all
menu:
"What was the murder weapon?"
"Scissors":
$ correct_answer_points += 0
"Gun":
$ correct_answer_points += 0
"Knife":
$ correct_answer_points += 1
menu question2:
"Who was the Murderer?"
or
Code: Select all
menu:
"What was the murder weapon?"
"Scissors":
$ correct_answer_points += 0
"Gun":
$ correct_answer_points += 0
"Knife":
$ correct_answer_points += 1
menu:
"Who was the Murderer?"
-
dGameBoy101b
- Regular
- Posts: 31
- Joined: Sun Aug 12, 2018 8:32 am
- itch: dgameboy101b
-
Contact:
#3
Post
by dGameBoy101b » Fri Aug 07, 2020 9:27 am
A more flexible way of storing the answers would be to use a list. This could allow you make more unique bad endings or easily change the correct answer later.
Code: Select all
$ response = []
menu:
"What was the murder weapon?"
"Scissors":
$ response.append("scissors")
"Gun":
$ response.append("gun")
"Knife":
$ response.append("knife")
menu:
"Who was the murderer?"
"Nozomi":
$ response.append("nozomi")
"Maki":
$ response.append("maki")
"Chika":
$ response.append("chika")
if response == ["knife", "maki"]:
"Correct!"
elif response == ["knife", "nozomi"]:
nozomi "You think I'd use that dinky little knife? Hah!"
else:
"Wrong!"
Users browsing this forum: Google [Bot]