defining with textbutton

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
lovebby
Regular
Posts: 106
Joined: Mon Sep 09, 2013 12:24 am
Deviantart: lovebby
Contact:

defining with textbutton

#1 Post by lovebby »

hey guys im trying to define whether the choice in a text button is False or True, but the way I set it up has me stumped.

Code: Select all

$trivia_question_list = ["Where's my dog","Where's my mom?"]

    if trivia_question == "Where's my dog?":
        $trivia_choice_1, trivia_choice_2, trivia_choice_3 = "Tavern","Home","Garden"
        #could i define the choices here as true/false?
        
    if trivia_question == "Where's my mom?":
        $trivia_choice_1, trivia_choice_2, trivia_choice_3 = "Park","School","Living Room"
    
screen trivia_screen:
    hbox xalign .5 yalign 0.6:
        textbutton"[trivia_question]"
            
    hbox xalign 0.5 yalign 0.8 spacing 80:
        textbutton "[trivia_choice_1]":      
            action Jump("trivia_choice_1")
        textbutton "[trivia_choice_2]":
            action Jump("trivia_choice_2")
        textbutton "[trivia_choice_3]":
            action Jump("trivia_choice_3")   

label wrong_ answer:
    "That's wrong!"      
    
label right_answer:
    "Woah you knew!"
        
    return
Should i be defining the answer as true/false before calling the screen?

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: defining with textbutton

#2 Post by Per K Grok »

lovebby wrote: Sun Apr 26, 2020 1:36 am hey guys im trying to define whether the choice in a text button is False or True, but the way I set it up has me stumped.

This could be a way of doing it.

Code: Select all

define trivia_question=[["Where's my dog","Tavern","Home","Garden", 3], ["Where's my mom","Park","School","Living Room", 2]]

screen trivia_screen:
    hbox xalign .5 yalign 0.6:
        text "[quest]"

    hbox xalign 0.5 yalign 0.8 spacing 80:
        textbutton "[answ1]":
            if correct==1:
                action Jump("right_answer")
            else:
                action Jump ("wrong_answer")
        textbutton "[answ2]":
            if correct==2:
                action Jump("right_answer")
            else:
                action Jump ("wrong_answer")
        textbutton "[answ3]":
            if correct==3:
                action Jump("right_answer")
            else:
                action Jump ("wrong_answer")

------------------------------------------------------------------------
-----------------------------------------------------------------------

label questions:
    $ q=renpy.random.randint(0,len(trivia_question)-1)
    $ quest= trivia_question[q][0]
    $ answ1= trivia_question[q][1]
    $ answ2= trivia_question[q][2]
    $ answ3= trivia_question[q][3]
    $ correct= trivia_question[q][4]
    call screen trivia_screen

label wrong_answer:
    "That's wrong!"
    jump questions

label right_answer:
    "Woah you knew!"
    jump questions

What you have here is a list of questions. Each question is a list in its own, containing the question, the three answer options, and which option is correct 1, 2 or 3. The questions are randomly chosen. You can add more questions in the same format to the trivia_question list.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]