What I am trying to accomplish:
I want to make a quiz where the three "wrong" answers are randomized and not set like they are in the list. I'm planning on making it to help learn Lithuanian so I'd want it pick wrong answers from a second list. I can create the second list like I did the first but I have no idea how to work it into the system. I know how to do this in C++ but this Python setup is different and I couldn't get it to work how I thought it would so I completely scratched that and need some pointers in the right direction.
This is the code I was using from Alex in another post:
Code: Select all
# Function that will shuffle answers
init python:
def shuffle_answers(x):
renpy.random.shuffle(x)
return x
# The game starts here.
label start:
# list of all possible questions
# it consist of dictionaries, that describe each question:
# key "question" has value of a question, key "category" makes sense for bot, key "answer" is a list of answers, that are lists [answer itself, right/wrong]
# the order of this keys is not matter
$ q_list = [
{"question": "Taip", "answer": [ ["Yes", "right"], ["q", "wrong"], ["e", "wrong"], ["r", "wrong"] ]},
{"question": "Labas Rytas", "answer": [ ["Hello", "right"], ["green", "wrong"], ["don\'t know", "wrong"], ["XoX", "wrong"] ]},
{"question": "Labas Vakaras", "answer": [ ["Good Afternoon", "right"], ["5", "wrong"], ["100", "wrong"], ["42", "wrong"] ]},
]
# game variables
#####
$ right_answers = 0 # result of quiz game
$ quiz_length = 2 # number of questions in one game
$ q_to_ask = [] # list of questions to ask in one game
# let's choose some questions to play with
while len(q_to_ask) < quiz_length: # will work until we'll get enough questions for quiz
$ a = renpy.random.choice (q_list) # randomly pick a question from a list of all questions
if a not in q_to_ask: # this question will be added only if we don't have it yet
$ q_to_ask.append (a)
label quize_game: # game loop
$ a = renpy.random.choice (q_to_ask) # randomly pick the question from a list
$ q_to_ask.remove (a) # remove it from list to not to ask it twice
$ b = shuffle_answers (a["answer"]) # let's shuffle answers
# ugly part... next variables are necessary to fill menu
$ question = a["question"]
$ category = a["category"]
$ answ_0 = b[0][0]
$ answ_1 = b[1][0]
$ answ_2 = b[2][0]
$ answ_3 = b[3][0]
menu:
"Category - [category]\nQ - [question]"
"[answ_0]":
if b[0][1] == "right": # checks the description of question if it's the right one
$ right_answers += 1
"That's true."
else:
"Nope."
"[answ_1]":
if b[1][1] == "right":
$ right_answers += 1
"That's true."
else:
"Nope."
"[answ_2]":
if b[2][1] == "right":
$ right_answers += 1
"That's true."
else:
"Nope."
"[answ_3]":
if b[3][1] == "right":
$ right_answers += 1
"That's true."
else:
"Nope."
$ quiz_length -= 1
if quiz_length > 0:
jump quize_game
"The result is - [right_answers]"