Well, when we have a list ('total_q_result') and appending another list to it ('q_result'), we'll have a list with one item (appended list). When we'll append another list, 'total_q_result' list will have two items (two appended lists).
The function 'my_add_to_list_func' appends each item of one list ('q_result') to another list ('total_q_result') separately, So 'total_q_result' list will have all items of appended lists as its own items.
I've changed quiz_result screen for both variants of keeping score.
Code: Select all
init python:
def shuffle_answers(x):
renpy.random.shuffle(x)
return x
def my_add_to_list_func(res_list, total_list):
for i in res_list:
total_list.append(i)
default q_result = []
default right_answers = 0
default wrong_answers = 0
default quiz_length = 0
default total_q_result = []
default total_right_answers = 0
default total_wrong_answers = 0
default total_quiz_length = 0
default total_res = []
screen quiz_result():
####
# Variant 1 - total result of all quizzes
#
frame:
xalign 0.05
yalign 0.5
xsize int(config.screen_width * 0.4)
side 'c':
area (0, 0, int(config.screen_width * 0.4), int(config.screen_height * 0.7))
viewport id 'vp_1':
draggable True
mousewheel True
yinitial 0.0
vbox:
spacing 25
null
text "Result of Quizzes ({} out of {})".format(total_right_answers, total_quiz_length) size 55 xalign 0.5
null
for i, entry in enumerate(total_q_result): # show each entry in total_q_result with the number "i"
text "{}. {} - {} ({}).".format(i+1, entry[0], entry[1], entry[2]) justify True
null
#
####
####
# Variant 2 - results of each quiz
#
frame:
xalign 0.95
yalign 0.5
xsize int(config.screen_width * 0.4)
side 'c':
area (0, 0, int(config.screen_width * 0.4), int(config.screen_height * 0.7))
viewport id 'vp_2':
draggable True
mousewheel True
yinitial 0.0
vbox:
spacing 25
for each_quiz in total_res:
vbox:
spacing 25
null
text "Result of {} ({} out of {})".format(each_quiz["quiz_name"], each_quiz["right_answers"], each_quiz["quiz_lenght"]) size 55 xalign 0.5
null
for i, entry in enumerate(each_quiz["quiz_result"]): # show each entry in q_result with the number "i"
text "{}. {} - {} ({}).".format(i+1, entry[0], entry[1], entry[2]) justify True
null
#
####
default q_list_1 = [
{"question": "is an electronic device that manipulates information, or data. It has the ability to store, retrieve, and process data.?", "answer": [ ["computer", "right"], ["cpu", "wrong"], ["modem", "wrong"], ["internet", "wrong"] ], "category": "multiple choice"},
{"question": "is the primary component of a computer that processes instructions. It runs the operating system and applications, constantly receiving input from the user or active software programs. It processes the data and produces output, which may stored by an application or displayed on the screen.?", "answer": [ ["cpu", "right"], ["computer", "wrong"], ["motherboard", "wrong"], ["internet", "wrong"] ], "category": "multiple choice"},
{"question": "is a primary memory. This memory is used inside the computer to hold programs and data while it is running.?", "answer": [ ["ram", "right"], ["hard drive", "wrong"], ["flashdrive", "wrong"], ["rom", "wrong"] ], "category": "multiple choice"},
{"question": "It is a part of a network. It is a special computer that users on the network can access to carry out a particular job.", "answer": [ ["server", "right"], ["lan cable", "wrong"], ["router", "wrong"], ["computer", "wrong"] ], "category": "multiple choice"},
{"question": "After adding and removing any other system components, make sure that you unplug your power supply. ", "answer": [ ["false", "right"], ["true", "wrong"] ], "category": "true or false"},
{"question": "With an effective cooling fan, the CPU can overheat and cause damage to both CPU and the motherboard. ", "answer": [ ["false", "right"], ["true", "wrong"] ], "category": "true or false"},
{"question": "Failure to do the proper jumper setting may cause damage to your CPU. ", "answer": [ ["true", "right"], ["false", "wrong"] ], "category": "true or false"},
{"question": "Test the computer, insuring that it meets the necessary system requirements before booting up.", "answer": [ ["false", "right"], ["true", "wrong"] ], "category": "true or false"}
]
default q_list_2 = [
{"question": "is an electronic device that manipulates information, or data. It has the ability to store, retrieve, and process data.?", "answer": [ ["computer", "right"], ["cpu", "wrong"], ["modem", "wrong"], ["internet", "wrong"] ], "category": "multiple choice"},
{"question": "is the primary component of a computer that processes instructions. It runs the operating system and applications, constantly receiving input from the user or active software programs. It processes the data and produces output, which may stored by an application or displayed on the screen.?", "answer": [ ["cpu", "right"], ["computer", "wrong"], ["motherboard", "wrong"], ["internet", "wrong"] ], "category": "multiple choice"},
{"question": "is a primary memory. This memory is used inside the computer to hold programs and data while it is running.?", "answer": [ ["ram", "right"], ["hard drive", "wrong"], ["flashdrive", "wrong"], ["rom", "wrong"] ], "category": "multiple choice"},
{"question": "It is a part of a network. It is a special computer that users on the network can access to carry out a particular job.", "answer": [ ["server", "right"], ["lan cable", "wrong"], ["router", "wrong"], ["computer", "wrong"] ], "category": "multiple choice"},
{"question": "After adding and removing any other system components, make sure that you unplug your power supply. ", "answer": [ ["false", "right"], ["true", "wrong"] ], "category": "true or false"},
{"question": "With an effective cooling fan, the CPU can overheat and cause damage to both CPU and the motherboard. ", "answer": [ ["false", "right"], ["true", "wrong"] ], "category": "true or false"},
{"question": "Failure to do the proper jumper setting may cause damage to your CPU. ", "answer": [ ["true", "right"], ["false", "wrong"] ], "category": "true or false"},
{"question": "Test the computer, insuring that it meets the necessary system requirements before booting up.", "answer": [ ["false", "right"], ["true", "wrong"] ], "category": "true or false"}
]
# etc.
label quiz_game(questions_list, q_length):
$ q_list = questions_list
$ q_result = [] # the question that is asked of the quiz store in here
# game variables
$ right_answers = 0 # result of quiz game
$ wrong_answers = 0 # result of wrong answer
$ quiz_length = q_length # number of questions in one game
# let's choose some questions to play with
$ q_to_ask = renpy.random.sample(q_list, quiz_length) # list of questions to ask in one game
label quiz_game_loop: # game loop
$ a = q_to_ask.pop() # pick the question (it will be removed from the list)
python: # let's shuffle answers
b = []
for q in shuffle_answers (a["answer"]):
b.append((q[0], q)) # (answer to show, [answer, 'right/wrong'])
# the question
$ narrator("category - {}\nQuestion\n- {}".format(a["category"], a["question"]), interact=False)
# the answers - result will be the chosen answer
$ res = renpy.display_menu(b)
$ result = res[1] # ("right"/"wrong")
$ answer = res[0] # answer (text)
# evaluate the result
if result == "right":
$ right_answers += 1
"That's true !"
else:
$ wrong_answers += 1
"Nope!"
# store the question and chosen answer in q_result
$ q_result.append([a["question"], answer, result])
if q_to_ask: # if we still got questions to ask
jump quiz_game_loop
return # return to game
label endofquiz:
window hide
# let's show the result of the quiz
show screen quiz_result
$ renpy.pause()
hide screen quiz_result
return # return to game
# The game starts here.
label start:
"Quiz 1"
call quiz_game(q_list_1, 3) # calling a quiz, passing name of questions list and quiz length
####
# Variant 1
$ my_add_to_list_func(q_result, total_q_result)
$ total_right_answers += right_answers
$ total_quiz_length += quiz_length
#
####
####
# Variant 2
$ total_res.append(
{
'quiz_name': 'Quiz 1',
'quiz_result': q_result,
'right_answers': right_answers,
'quiz_lenght': quiz_length,
}
)
#
####
call endofquiz
"So, you've done."
"Quiz 2"
call quiz_game(q_list_2, 4) # calling a quiz, passing name of questions list and quiz length
####
# Variant 1
$ my_add_to_list_func(q_result, total_q_result)
$ total_right_answers += right_answers
$ total_quiz_length += quiz_length
#
####
####
# Variant 2
$ total_res.append(
{
'quiz_name': 'Quiz 2',
'quiz_result': q_result,
'right_answers': right_answers,
'quiz_lenght': quiz_length,
}
)
#
####
call endofquiz
"That's all for now."
return