Need help with bug in Random Image Main Menu slideshow code

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
Freshenstein
Newbie
Posts: 4
Joined: Thu May 26, 2022 5:19 pm
Contact:

Need help with bug in Random Image Main Menu slideshow code

#1 Post by Freshenstein »

Here is the code I have. It works but there's an odd glitch. It will show an image for a split second without any transition before showing another image with the transition and pausing for the right amount of time.

Code: Select all

init python:
    def rnd_mm_selector(st, at):
        rand = renpy.random.randint(1, 554)
        return Image("mainmenu/mm-" + str(rand) + ".jpg"), None

image mainmenu_img = DynamicDisplayable(rnd_mm_selector)
image mainmenu:
    "mainmenu_img" with rng_transition
    pause 3
    repeat
"rng_transition" is a custom bit of code that generates a random dissolve transition with one of 339 different wipes. In case you need the rng_transition code here it is:

Code: Select all

init python:
    def rnd_image_selector(st, at):
        rnd = renpy.random.randint(1, 329)
        return Image("wipes/" + str(rnd) + ".jpg"), None

image rnd_transition_alpha = DynamicDisplayable(rnd_image_selector)
define rng_transition = ImageDissolve("rnd_transition_alpha", 1.0)
Like I said, the code works, just with a weird glitch that flashes a pic for not even a second. If anyone can clue me in on what I did wrong, I would appreciate it.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Need help with bug in Random Image Main Menu slideshow code

#2 Post by Ocelot »

I am surprised this code works as well, as you describe.

Screens can be redrawn and code inside them executed multiple times at any moment (during screen prediction, when interaction is restarted, when some variables change, when game is minimised/restored...)

What you see is probably result of screen code executed again, and rnd_mm_selector or rnd_image_selector returning different displayable form what it was before. As there was significant change, transition is cancelled and new one takes it place.

I would expect more of these "restarts" when your main menu will became more complex.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Google [Bot]