Noob's question about a math game

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
morrris
Newbie
Posts: 11
Joined: Fri Jun 21, 2019 3:05 am
Contact:

Noob's question about a math game

#1 Post by morrris »

Code: Select all

define e = Character("Eileen")

init:

    $ test = renpy.random.randint(10,13)
    $ c_p = renpy.random.randint(10, 99)
    $ c_p1 = c_p +6
    $ c_p2 = c_p +12
    $ c_p3 = c_p +18
    $ c_p4 = c_p +24
    $ c_p5 = c_p +1
    $ c_p6 = c_p -2
    $ c_p7 = c_p -1


label start:

    e "Solve this sequence for X:"
    e "X [c_p1] [c_p2] [c_p3] [c_p4]"

    if test == 10:
        jump test1

    if test == 11:
        jump test2

    if test == 12:
        jump test3

    if test == 13:
        jump test4

    label test1:

        menu:
            "[c_p5]":
                
                jump teststop
            "[c_p6]":
                
                jump teststop
            "[c_p]":
                
                jump testgood
            "[c_p7]":
                
                jump teststop

    label test2:

        menu:
            "[c_p]":
                
                jump testgood
            "[c_p6]":
                
                jump teststop
            "[c_p5]":
                
                jump teststop
            "[c_p7]":
                
                jump teststop

    label test3:

        menu:
            "[c_p5]":
                
                jump teststop
            "[c_p]":
                
                jump testgood
            "[c_p6]":
                
                jump teststop
            "[c_p7]":
                
                jump teststop

    label test4:

        menu:
            "[c_p5]":
                
                jump teststop
            "[c_p6]":
                
                jump teststop
            "[c_p7]":
                
                jump teststop
            "[c_p]":
                
                jump testgood

    label teststop:
        e "Wrong..."
        return

    label testgood:
        e "Great job!"

    
    return
Hi everyone. I am new and my code is very very very basic.
A question please: Each time I run it, my random correct answer [c_p] is random only at first. How can I make it random again every time without restart? Thank you in advance.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Noob's question about a math game

#2 Post by xavimat »

Don't put the random and variables part inside an "init" block ("init" means that it will be executed only once, at init time).
Put the random and variables inside a label, and call that label every time you want fresh numbers.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Noob's question about a math game

#3 Post by IrinaLazareva »

Not exactly on the subject... As for your the "test" construction:

Code: Select all

    if test == 10:
        jump test1

    if test == 11:
        jump test2

    if test == 12:
        jump test3

    if test == 13:
        jump test4
I recommend you to read this article
https://patreon.renpy.org/shuffle-menu.html

morrris
Newbie
Posts: 11
Joined: Fri Jun 21, 2019 3:05 am
Contact:

Re: Noob's question about a math game

#4 Post by morrris »

Thank you both. You have been a great help!

Post Reply

Who is online

Users browsing this forum: Donmai