[Solved] Randomly appearing images are skipping.

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
K-PSZH
Regular
Posts: 37
Joined: Sun May 15, 2022 10:34 am
Soundcloud: K-PSZH
Location: Russia
Contact:

[Solved] Randomly appearing images are skipping.

#1 Post by K-PSZH »

So, I added a randomly choosen image to my screen.

Code: Select all

screen main_menu():
    tag menu
    add gui.main_menu_background
    add renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])
But they're changing, when I press Ctrl. Is there a way to disable button in main menu or just fix the problem?
Last edited by K-PSZH on Sun May 22, 2022 5:34 am, edited 1 time in total.
Missing/forgetting a lot of simplest things and ask about them here.

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

Re: Randomly appearing images are skipping.

#2 Post by Alex »

K-PSZH wrote: Sat May 21, 2022 3:46 pm So, I added a randomly choosen image to my screen.

Code: Select all

screen main_menu():
    tag menu
    add gui.main_menu_background
    add renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])
But they're changing, when I press Ctrl. Is there a way to disable button in main menu or just fix the problem?
This line of code picks random image

Code: Select all

add renpy.random.choice(...)
and it will pick random image every time screen will be redrawn (and it happens from time to time).

To prevent image change try it like

Code: Select all

screen main_menu():
    default random_img = None # screen variable

    # choose image if not yet
    if not random_img:
        $ random_img = renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])

    tag menu
    add gui.main_menu_background
    add random_img
edit: corrected the code
Last edited by Alex on Sat May 21, 2022 7:33 pm, edited 1 time in total.

User avatar
K-PSZH
Regular
Posts: 37
Joined: Sun May 15, 2022 10:34 am
Soundcloud: K-PSZH
Location: Russia
Contact:

Re: Randomly appearing images are skipping.

#3 Post by K-PSZH »

Alex wrote: Sat May 21, 2022 4:16 pm To prevent image change try it like

Code: Select all

screen main_menu():
    default random_img = None # screen variable

    # choose image if not yet
    if not random_img:
        random_img = renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])

    tag menu
    add gui.main_menu_background
    add random_img

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 295: u'random_img' is not a keyword argument or valid child for the screen statement.
    random_img = renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])
              ^
Missing/forgetting a lot of simplest things and ask about them here.

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

Re: Randomly appearing images are skipping.

#4 Post by Alex »

K-PSZH wrote: Sat May 21, 2022 7:02 pm
Alex wrote: Sat May 21, 2022 4:16 pm To prevent image change try it like

Code: Select all

screen main_menu():
    default random_img = None # screen variable

    # choose image if not yet
    if not random_img:
        random_img = renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])

    tag menu
    add gui.main_menu_background
    add random_img

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 295: u'random_img' is not a keyword argument or valid child for the screen statement.
    random_img = renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])
              ^
Oops, my fault forgot the $ sign - should be

Code: Select all

$ random_img = renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])

User avatar
K-PSZH
Regular
Posts: 37
Joined: Sun May 15, 2022 10:34 am
Soundcloud: K-PSZH
Location: Russia
Contact:

Re: Randomly appearing images are skipping.

#5 Post by K-PSZH »

Alex wrote: Sat May 21, 2022 7:32 pm Oops, my fault forgot the $ sign - should be

Code: Select all

$ random_img = renpy.random.choice(["gui/main_menu/characters/1.png", "gui/main_menu/characters/2.png", "gui/main_menu/characters/3.png"])
Worked!
Missing/forgetting a lot of simplest things and ask about them here.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot