looping problem i cant jump to another label

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.
Post Reply
Message
Author
User avatar
Mjhay
Regular
Posts: 61
Joined: Sat Jan 16, 2021 2:29 pm
Location: Philippines
Contact:

looping problem i cant jump to another label

#1 Post by Mjhay » Thu May 06, 2021 1:20 am

im trap in the loop in my quiz game
how can i jump to next label?

im trying to make a quiz 1-10 multiple choice and 11-10 is true or false.
and when in in the category2 the true or false, its always back to category 2 like infinite loop. i dont know what logic should i use to make it. :lol:

is there any other way to fix this?
here the quiz code its working, problem is the loop:

Code: Select all

$ q_list = [
    {"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"}
    ]

    $ q_listtof1 = [
    {"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"}
    ]

    $ q_result = []    ## the question that is asked of the quiz store in here
    $ q_resulttof1 = []

    # game variables
    $ right_answers = 0     # result of quiz game
    $ wrong_answers = 0     # result of wrong answer
    $ quiz_length = 10      # number of questions in one game
    $ quiz_length1 = 10
    $ unlocked = [right_answers]
    $ q_asked=0
    $ passingScore = 15

    # 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

    show screen countdown ##  timer

    label quize_game:             # 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 - {}\n\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":
            $ right_answers += 1
        else:
            $ wrong_answers += 1
        # store the question and chosen answer in q_result
        $ q_result.append([a["question"], answer, result])
        $ q_resulttof1.append([a["question"], answer, result])

        $ q_asked += 1

        if q_to_ask: # if we still got questions to ask
            jump quize_game
    
    doy "get Ready for the test II{p}Category : True or False"  ### this is the 2nd category #####

    $ q_to_ask = renpy.random.sample(q_listtof1, quiz_length1) # list of questions to ask in one game
    jump quize_game              ###### this is my problem if how can i jump to endofquiz label? if i change it to endofquiz category 2 will not display. 


    label endofquiz:

        if [right_answers] == [quiz_length]:
            stop music fadeout 1
            jump perfect_score

        if [right_answers] < [passingScore]:
            stop music fadeout 1
            jump zero_score
        else:
            stop music fadeout 1
            hide screen countdown

    doy "Your score is = [right_answers] out of [quiz_length]"
    doy "Good job! %(player_name)s you passed the 1st level.{p}You have unlocked the 2nd leveL, the SET-UP COMPUTER NETWORK"

anyone can help me ? thank in advance

User avatar
Alex
Lemma-Class Veteran
Posts: 2680
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: looping problem i cant jump to another label

#2 Post by Alex » Thu May 06, 2021 7:28 pm

You need to make quiz game a separate label and call it for each set of questions. And don't forget to return back to the game from the quiz label.

Try

Code: Select all

init python:
    
    def shuffle_answers(x):
        renpy.random.shuffle(x)
        return x
        
default q_result = []

screen quiz_result():
            
    frame:
        xalign 0.5
        yalign 0.5
        xsize int(config.screen_width / 2)
        
        vbox:
            spacing 25
            null
            text "Result of Quiz ({} out of {})".format(right_answers, quiz_length) size 55 xalign 0.5
            null
            for i, entry in enumerate(q_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, quiz_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 = quiz_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
            
        
    label endofquiz:
        # let's show the result of the quize
        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
    "So, you've done." # here we will return
    "Quiz 2"
    call quiz_game(q_list_2, 4) # calling a quiz, passing name of questions list and quiz length
    "That's all for now." # here we will return

User avatar
Mjhay
Regular
Posts: 61
Joined: Sat Jan 16, 2021 2:29 pm
Location: Philippines
Contact:

Re: looping problem i cant jump to another label

#3 Post by Mjhay » Sat May 08, 2021 1:58 pm

Alex wrote:
Thu May 06, 2021 7:28 pm
You need to make quiz game a separate label and call it for each set of questions. And don't forget to return back to the game from the quiz label.
yeah thanks for that alex it works now.
but how can i append and store the q_list1 and q_list2 in one variable ? or should separate them? i want to display that two list, the multiple choice and true or false as one in the quiz_result and combine there score to make the average as one.

here is the quiz result:

Code: Select all

screen quiz_result():
    side "c b r":
        area (350, 25, 650, 650)

        viewport id "vp":
            draggable True
            xfill True
            yfill True

            frame:
                xfill True
                yminimum 650

                vbox:
                    spacing 5
                    null
                    text "Result of Quiz" size 45 xalign 0.5
                    null
                    if q_to_ask>0:
                        text "{}".format(right_answers*100/25) + "%" size 60 xalign 0.5
                        null

                    text "({} out of {})\n".format(right_answers, quiz_length + quiz_length) size 30 xalign 0.5
                    null
                    null
                    text "Name: {}\n".format(player_name) size 30 xalign 0.01
                    null

                    vbox:
                        spacing 25
                        text "{color=#0080c0}TEST I Multiple Choice{/color}" size 30 xalign 0.5
                        for i, entry in enumerate(q_result): # show each entry in q_result with the number "i"
                            text "{}. {} \n     - {} ({}).".format(i+1, entry[0], entry[1], entry[2]) justify True
                        null
                        text "{color=#0080c0}TEST II True or False{/color}" size 30 xalign 0.5
                        for i, entry in enumerate(q_result1): # show each entry in q_result with the number "i"
                            text "{}. {} \n     - {} ({}).".format(i+1, entry[0], entry[1], entry[2]) justify True

User avatar
Alex
Lemma-Class Veteran
Posts: 2680
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: looping problem i cant jump to another label

#4 Post by Alex » Sat May 08, 2021 5:11 pm

...but how can i append and store the q_list1 and q_list2 in one variable ? or should separate them? i want to display that two list, the multiple choice and true or false as one in the quiz_result and combine there score to make the average as one. ...
You can make a variable(s) or list to store the final result of all quizzes, and modify/append them right after each quiz is done.
Quiz game uses 'q_result', 'right_answers ' and 'quiz_length' to keep the game result. So you can try to make it like

Code: Select all

default total_q_result = []
default total_right_answers = 0
default total_quiz_length = 0

# 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
    ####
    $ total_q_result.append(q_result)
    $ total_right_answers  += right_answers 
    $  total_quiz_length  += quiz_length
    ####
    "So, you've done." # here we will return
    "Quiz 2"
    call quiz_game(q_list_2, 4) # calling a quiz, passing name of questions list and quiz length
    ####
    $ total_q_result.append(q_result)
    $ total_right_answers  += right_answers 
    $  total_quiz_length  += quiz_length
    ####
    "That's all for now." # here we will return
In quiz_result screen you could show the total result of all quizzes.

The other way is to make a list where each item will be a dictionary with keys like 'quiz_name', 'quiz_result', 'right_answers' and 'quiz_lenght'. So you could set the values after each quiz.

Code: Select all

default total_res = []

# 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
    ####
    $ total_res.append(
        'quiz_name': 'Quiz 1',
        'quiz_result': q_result,
        'right_answers': right_answers,
        'quiz_lenght': quiz_length,
        )
    ####
    "So, you've done." # here we will return
    "Quiz 2"
    call quiz_game(q_list_2, 4) # calling a quiz, passing name of questions list and quiz length
    ####
    $ total_res.append(
        'quiz_name': 'Quiz 2',
        'quiz_result': q_result,
        'right_answers': right_answers,
        'quiz_lenght': quiz_length,
        )
    ####
    "That's all for now." # here we will return
Then in quiz_result screen you could show results of each game separately.

User avatar
Mjhay
Regular
Posts: 61
Joined: Sat Jan 16, 2021 2:29 pm
Location: Philippines
Contact:

Re: looping problem i cant jump to another label

#5 Post by Mjhay » Sun May 09, 2021 7:45 am

Alex wrote:
Sat May 08, 2021 5:11 pm
...but how can i append and store the q_list1 and q_list2 in one variable ? or should separate them? i want to display that two list, the multiple choice and true or false as one in the quiz_result and combine there score to make the average as one. ...
You can make a variable(s) or list to store the final result of all quizzes, and modify/append them right after each quiz is done.
Quiz game uses 'q_result', 'right_answers ' and 'quiz_length' to keep the game result. So you can try to make it like

Code: Select all

default total_q_result = []
default total_right_answers = 0
default total_quiz_length = 0

# 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
    ####
    $ total_q_result.append(q_result)
    $ total_right_answers  += right_answers 
    $  total_quiz_length  += quiz_length
    ####
    "So, you've done." # here we will return
    "Quiz 2"
    call quiz_game(q_list_2, 4) # calling a quiz, passing name of questions list and quiz length
    ####
    $ total_q_result.append(q_result)
    $ total_right_answers  += right_answers 
    $  total_quiz_length  += quiz_length
    ####
    "That's all for now." # here we will return
In quiz_result screen you could show the total result of all quizzes.
well, i use this methods and it works. thanks to that :) and your second method was goes to error .
and the problem now is in the displaying of the quiz result screen , when total_q_result is inumerate, it is only 1 item because all the 10 question is inside in this 1 item. and that should be 10 items when the total_q_result is inumerate in the screen quiz rsult
hope you understand what i mean, i cant explain very much because im not good in english :(

User avatar
Alex
Lemma-Class Veteran
Posts: 2680
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: looping problem i cant jump to another label

#6 Post by Alex » Sun May 09, 2021 9:01 am

Mjhay wrote:
Sun May 09, 2021 7:45 am
...
Oops, sorry was a bit tired...((
It should be

Code: Select all

default total_q_result = []
default total_right_answers = 0
default total_quiz_length = 0

init python:
    def my_add_to_list_func(res_list, total_list):
        for i in res_list:
            total_list.append(i)

    
# 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
    ####
    $ my_add_to_list_func(q_result, total_q_result)
    $ total_right_answers  += right_answers 
    $ total_quiz_length  += quiz_length
    ####
    "So, you've done." # here we will return
    "Quiz 2"
    call quiz_game(q_list_2, 4) # calling a quiz, passing name of questions list and quiz length
    ####
    $ my_add_to_list_func(q_result, total_q_result)
    $ total_right_answers  += right_answers 
    $ total_quiz_length  += quiz_length
    ####
    "That's all for now." # here we will return
And for the second method - I've missed the braces

Code: Select all

    ####
    $ total_res.append(
        {
        'quiz_name': 'Quiz 1',
        'quiz_result': q_result,
        'right_answers': right_answers,
        'quiz_lenght': quiz_length,
        }
        )
    ####

User avatar
Mjhay
Regular
Posts: 61
Joined: Sat Jan 16, 2021 2:29 pm
Location: Philippines
Contact:

Re: looping problem i cant jump to another label

#7 Post by Mjhay » Sun May 09, 2021 10:47 am

Alex wrote:
Sun May 09, 2021 9:01 am
Mjhay wrote:
Sun May 09, 2021 7:45 am
...

Code: Select all

init python:
    def my_add_to_list_func(res_list, total_list):
        for i in res_list:
            total_list.append(i)
 
can i ask what is the use of that function?

and what variable should i use to enumerate? in screen quiz result

Code: Select all

            text "{color=#0080c0}TEST I Multiple Choice{/color}" size 30 xalign 0.5
                        for i, entry in enumerate(total_q_result): # show each entry in q_result with the number "i"
                            text "{}. {} \n     - {} ({}).".format(i+1, entry[0], entry[1], entry[2]) justify True
                        null
                        text "{color=#0080c0}TEST II True or False{/color}" size 30 xalign 0.5
                        for i, entry in enumerate(total_q_result): # show each entry in q_result with the number "i"
                            text "{}. {} \n     - {} ({}).".format(i+1, entry[0], entry[1], entry[2]) justify True
                        null

User avatar
Alex
Lemma-Class Veteran
Posts: 2680
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: looping problem i cant jump to another label

#8 Post by Alex » Sun May 09, 2021 4:35 pm

Mjhay wrote:
Sun May 09, 2021 10:47 am
...can i ask what is the use of that function?

and what variable should i use to enumerate? in screen quiz result...
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

User avatar
Mjhay
Regular
Posts: 61
Joined: Sat Jan 16, 2021 2:29 pm
Location: Philippines
Contact:

Re: looping problem i cant jump to another label

#9 Post by Mjhay » Mon May 10, 2021 9:39 pm

Alex wrote:
Sun May 09, 2021 4:35 pm
Mjhay wrote:
Sun May 09, 2021 10:47 am
...can i ask what is the use of that function?

and what variable should i use to enumerate? in screen quiz result...
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.
oh!! its done .. thank you alex :) i appreciated all of your help .. :D

User avatar
Mjhay
Regular
Posts: 61
Joined: Sat Jan 16, 2021 2:29 pm
Location: Philippines
Contact:

Re: looping problem i cant jump to another label

#10 Post by Mjhay » Mon May 17, 2021 7:27 am

Alex wrote:
Sun May 09, 2021 4:35 pm

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.
can i ask a last one? after displaying screen quiz result, it is possible to clear all the variable that store the q_result after displaying the screen quiz result. so that if i take another quiz the quizresult wont stack.
i want to clear all this varibales.

default total_q_result = []
default q_result = []
default total_res = []

User avatar
Alex
Lemma-Class Veteran
Posts: 2680
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: looping problem i cant jump to another label

#11 Post by Alex » Mon May 17, 2021 1:00 pm

Mjhay wrote:
Mon May 17, 2021 7:27 am
...i want to clear all this varibales.

default total_q_result = []
default q_result = []
default total_res = []
So, just set them to empty list right before the new quiz

Code: Select all

$ total_q_result = []
$ q_result = []
$ total_res = []

User avatar
Mjhay
Regular
Posts: 61
Joined: Sat Jan 16, 2021 2:29 pm
Location: Philippines
Contact:

Re: looping problem i cant jump to another label

#12 Post by Mjhay » Mon May 17, 2021 10:14 pm

Alex wrote:
Mon May 17, 2021 1:00 pm
Mjhay wrote:
Mon May 17, 2021 7:27 am
...i want to clear all this varibales.

default total_q_result = []
default q_result = []
default total_res = []
So, just set them to empty list right before the new quiz

Code: Select all

$ total_q_result = []
$ q_result = []
$ total_res = []
Yes but its already empty .
Thats the code
Is there a function that can clear that variable? Or is there anyy other way to do that?

User avatar
Alex
Lemma-Class Veteran
Posts: 2680
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: looping problem i cant jump to another label

#13 Post by Alex » Tue May 18, 2021 2:53 pm

Mjhay wrote:
Mon May 17, 2021 10:14 pm
Alex wrote:
Mon May 17, 2021 1:00 pm
Mjhay wrote:
Mon May 17, 2021 7:27 am
...i want to clear all this varibales.

default total_q_result = []
default q_result = []
default total_res = []
So, just set them to empty list right before the new quiz

Code: Select all

$ total_q_result = []
$ q_result = []
$ total_res = []
Yes but its already empty .
Thats the code
Is there a function that can clear that variable? Or is there anyy other way to do that?
Hm, sorry, I don't get the question...
By default this variables are empty lists

Code: Select all

default total_q_result = []
default q_result = []
default total_res = []
When you'll play some quizzes they will have some values.

If you want to play some more quizzes and want to keep score just for those quizzes, then set those variables to empty lists again.

Code: Select all

label start:
    # play first block of quizzes and keep total score for it

    $ total_q_result = []
    $ q_result = []
    $ total_res = []

    # play second block of quizzes and keep total score for second block
    # ???
Is this what you want to achieve?

User avatar
Mjhay
Regular
Posts: 61
Joined: Sat Jan 16, 2021 2:29 pm
Location: Philippines
Contact:

Re: looping problem i cant jump to another label

#14 Post by Mjhay » Tue May 18, 2021 10:51 pm

Alex wrote:
Tue May 18, 2021 2:53 pm
[quote=Mjhay post_id=542806 time=1621304070
Its ok now alex i get it .
I put it after calling the quiz game .

$ my_add_to_list_func(q_result, total_q_result)
$ total_q_result = []
$ q_result = []
$ total_res = []

Thanks for your help :)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Ocelot