and its working, EXCEPT when you run out of time on the LAST ITEM of quiz (5/5 items) . it goes to error.
the error is:
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 907, in script call
call quiz_game(q_listMC_1, 5) # calling a quiz, passing name of questions list and quiz length
File "game/script.rpy", line 584, in script
$ a = q_to_ask.pop() # pick the question (it will be removed from the list)
File "game/script.rpy", line 584, in <module>
$ a = q_to_ask.pop() # pick the question (it will be removed from the list)
IndexError: pop from empty list
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 907, in script call
call quiz_game(q_listMC_1, 5) # calling a quiz, passing name of questions list and quiz length
File "game/script.rpy", line 584, in script
$ a = q_to_ask.pop() # pick the question (it will be removed from the list)
File "C:\Users\isle\Documents\THESIS\renpy\renpy-7.3.5-sdk\renpy\ast.py", line 914, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\isle\Documents\THESIS\renpy\renpy-7.3.5-sdk\renpy\python.py", line 2028, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 584, in <module>
$ a = q_to_ask.pop() # pick the question (it will be removed from the list)
IndexError: pop from empty list
Windows-8-6.2.9200
Ren'Py 7.3.5.606
CSSTIME 1.0
Mon Jun 07 09:33:52 2021
here is the timer of the quiz:
Code: Select all
screen countdown(duration=20):
default time_remaining = duration
timer 1.0 repeat True action SetScreenVariable("time_remaining", max(time_remaining - 1.0, 0))
bar value AnimatedValue(time_remaining, duration) xsize 200 align (0.5, 0.15)
if time_remaining > 20:
text str(time_remaining) align(0.5, 0.08) color "#fff" size 50
elif time_remaining > 15:
text str(time_remaining) align(0.5, 0.08) color "#07a81e" size 50
elif time_remaining > 10:
text str(time_remaining) align(0.5, 0.08) color "#faf104" size 50
elif time_remaining > 5:
text str(time_remaining) align(0.5, 0.08) color "#eb6e08" size 50
elif time_remaining > 0:
text str(time_remaining) align(0.5, 0.08) color "#f00" size 50
else:
text str(time_remaining) align(0.5, 0.08) color "#f00" size 50
if time_remaining <= 0:
$ q_result.append([a["question"], "-", "Unanswered"]) ### if you runout of time it will display in result
timer 0.01 action [Jump('quize_game'), Hide("countdown")]
Code: Select all
default q_listMC_lo1 = [
{"question": "It 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"},
]
.
.
default q_listToF_lo1 = [
{"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": "After starting the installation, read carefully the documentation and procedures on any hardware and software settings that may be required", "answer": [ ["False", "right"], ["True", "wrong"] ], "category": "True or False"},
]
.
.
label quiz_game(questions_list, q_length):
# game variables
$ q_list = questions_list
$ q_result = [] # the question that is asked of the quiz store in here
$ right_answers = 0 # result of quiz game
$ wrong_answers = 0 # result of wrong answer
$ quiz_length = q_length # number of questions in one game
$ unlocked = [right_answers]
$ q_asked=0
$ passingScore = 3
# 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
$ q_asked=0
$ quiz_length = q_length
$ 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'])
show screen countdown # timer of the quiz
# the question
$ narrator("Category - {}\nQuestion - {}".format(a["category"], a["question"]), interact=False)
# the answers - result will be the chosen answer
#$ renpy.block_rollback()
$ res = renpy.display_menu(b)
$ result = res[1] # ("right"/"wrong")
$ answer = res[0] # answer (text)
# evaluate the result
if result == "right":
$ renpy.block_rollback()
$ right_answers += 1
else:
$ renpy.block_rollback()
$ wrong_answers += 1
# store the question and chosen answer in q_result
$ q_result.append([a["question"], answer, result])
$ q_asked += 1
if q_to_ask: # if we still got questions to ask
jump quiz_game_loop
return # return to game
label start:
.
.
"Quiz 1{p}Category - Multiple Choice"
call quiz_game(q_listMC_1, 5) # calling a quiz, passing name of questions list and quiz length
.
.
"Quiz 2{p}Category - True or False"
call quiz_game(q_listMC_1, 5) # calling a quiz, passing name of questions list and quiz length