[Solved] Making a random image show up like that?

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
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

[Solved] Making a random image show up like that?

#1 Post by Nanahs »

I'm trying to make a mini game.
In this mini game I would make a question. E.g. "Who would wake up at 3am to still food from the fridge?"
Then, when the person click the screen, an image of a character would appear randomly (being the answer). There are 5 characters images to show up.
I was trying that, but it keeps giving me different errors. I put this in scrip.

Code: Select all

label whocharactergame:
    
    scene bluepark
    with fade
    
init python:
    from random import randint
    " I'd make a queston here "
    
    $randPix = randint(1,5)    
    if randPix== 1:
        add "jhonpick.png" 

    elif randPix== 2:
        add "annapick.png" 

    else:
        add "georgepick.png" 

    else:
        add "kaylapick.png" 

    else:
        add "karenpick.png" 
I'm not sure if I can use "else" this many times, or what is wrong. Maybe there's a better way to do it.
Does anyone know?

Thanks :)
Last edited by Nanahs on Fri Oct 12, 2018 9:37 pm, edited 1 time in total.

pumpkin spike
Regular
Posts: 76
Joined: Fri Mar 09, 2018 6:13 pm
Projects: A Bureau of Monsters
itch: pumpkin-spike
Location: A Pumpkin Patch
Contact:

Re: Making a random image show up like that?

#2 Post by pumpkin spike »

Not 100% confident here, but I think you want to use 'elif' for as many cases as you'd like and 'else' once. 'else' should be used for when you've already listed all the other specific cases you wanted.

(Just thought I could give a pointer before someone more knowledgeable comes your way and answers this better ovo;; )
Image
WIP AllxAll game with turn based fighting (Demo 2.0 out!)

Image
WIP Yaoi game Demo 1.0 out! (haitus)

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: Making a random image show up like that?

#3 Post by xavimat »

There are some things to note here:
1. First of all, you can't mix python code and renpy code. The dialogue line " I'd make a queston here " has no meaning in python.
2. "init" is used only for the init phase, not for the actual game.
3. "add" is renpy-screen-language, different from renpy-label-language.
4. renpy has its own random module, use that to avoid problems with rollback.
5. To make a minigame better use screen language.
6. As pumpkin has said, only one "else" is allowed.

I haven't fully understood what do you mean with "minigame" in your example. There is a question and an image showing with a simple click. Probably you are thinking on some interactivity. Anyway, what you have described can be achieved this way:

Code: Select all

label whocharactergame:    
    scene bluepark with fade
    "Who would wake up at 3am to still food from the fridge?"
    $ culprit = renpy.random.choice(["jhonpick", "annapick", "annapick", "kaylapick"])
    show expression culprit
    "It was [culprit]!"
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
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: Making a random image show up like that?

#4 Post by Nanahs »

Thank you so much guys! :)
Sometimes I still get confused about where I can use a certain code hah
I also found a solution:

Code: Select all

image chracterwho:
        choice:
            "images/jhonpick.png"
        choice:
            "images/annapick.png"


label whocharactergame:
    
    scene bluepark
    with fade
    
    "Who would wake up at 3am to still food from the fridge?"
    show characterwho

Post Reply

Who is online

Users browsing this forum: Google [Bot], SONTSE