Loading new images from disk while game is running

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
Nephthys
Newbie
Posts: 5
Joined: Sun Jan 19, 2014 4:51 pm
Contact:

Loading new images from disk while game is running

#1 Post by Nephthys » Thu Sep 01, 2022 6:19 pm

In brief, is there any workaround that would allow me to load a new image via Python after init?

I am downloading new image files while the game is running, and would like to display them as background/character images. However, I cannot run renpy.image outside of init. I've tried using a DynamicImage, but even then it doesn't seem like it will load any image file that did not exist when the game started? Any new images files that I try to load with the DynamicImage wildcard come back as 'could not find image'.

The only thing that has kind of worked is to have a template image created, declare that image in the init and then overwrite it during gameplay. The file only seems to load once show is called, and then it loads the newly downloaded image. However this only works once, as the image after that seems to reside in memory and does not get reloaded even if the file on disk is replaced again and show called afterwards.

Is there anything I can do to find and display new images after the game has started?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Loading new images from disk while game is running

#2 Post by Imperf3kt » Thu Sep 01, 2022 6:53 pm

I haven't yet worked out how to use the images / text on any screen other than news() yet, but there's viewtopic.php?f=8&t=65185&p=554749&hilit=News#p554749
And alternatively viewtopic.php?f=51&t=65233&p=554917&hilit=News#p554915
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
Andredron
Miko-Class Veteran
Posts: 535
Joined: Thu Dec 28, 2017 2:37 pm
Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
Location: Russia
Contact:

Re: Loading new images from disk while game is running

#3 Post by Andredron » Thu Sep 01, 2022 7:00 pm

Imperf3kt wrote:
Thu Sep 01, 2022 6:53 pm
I haven't yet worked out how to use the images / text on any screen other than news() yet, but there's viewtopic.php?f=8&t=65185&p=554749&hilit=News#p554749
And alternatively viewtopic.php?f=51&t=65233&p=554917&hilit=News#p554915
viewtopic.php?f=8&t=58678

As an option, make such a gallery of screenshots ...

But your version is more advanced
I'm writing a Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Help me to register in QQ International

Honest Critique

User avatar
enaielei
Regular
Posts: 114
Joined: Fri Sep 17, 2021 2:09 am
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Loading new images from disk while game is running

#4 Post by enaielei » Thu Sep 01, 2022 7:10 pm

How about saving/downloading the image file in the config.savedir or %appdata% path, then load it as a path file?

Code: Select all

init python:
  APPDATA = config.savedir.replace("\\", "/")

screen test():
  add "{}/test.png".format(APPDATA)

Nephthys
Newbie
Posts: 5
Joined: Sun Jan 19, 2014 4:51 pm
Contact:

Re: Loading new images from disk while game is running

#5 Post by Nephthys » Fri Sep 02, 2022 6:54 am

Thank you! The news module in particular is a great example - im.Data() is a function I hadn't seen before, and that makes some of what I'm doing a lot easier.

I'm starting to understand the different ways in which images are handled better. So I guess the main issue I'm having now is - I can make a displayable using im.Data(), but I still don't see how I can show that displayable in the way that I want.

renpy.show() needs an image string, which I can only get via renpy.image, which takes a displayable as an input, but renpy.image can only be run on init.

Is there any easy way to show a displayable without calling renpy.image? I have a displayable, I want to display it as the background image, but I don't understand what the easiest way to show a new background would be without having to do renpy.image. The news example uses a screen, but I don't understand how that bypasses the neeed for renpy.show/renpy.image?

Nephthys
Newbie
Posts: 5
Joined: Sun Jan 19, 2014 4:51 pm
Contact:

Re: Loading new images from disk while game is running

#6 Post by Nephthys » Fri Sep 02, 2022 7:19 am

Oh I think I finally got it!

Took a while of digging through documentation, but I've finally realised that renpy.show() doesn't just have to use the name of an image registered by renpy.image(). If you use the optional 'what' argument you can pass a displayable directly to renpy.show() and bypass the need for renpy.image(). So confusing :D

Post Reply

Who is online

Users browsing this forum: Google [Bot]