[...] after changing config.periodic_callback.append( hide_img_mi )
to renpy.config.periodic_callbacks.append( hide_img_mi )
Oops. This one is on PyTom, what Idea to have two configuration value that do the same things, one as direct callback, the other as list of callback. I'm not even sure that the first one is really still used nowadays.
Which is great, but option two: use
You must be registered to see the links
sounds better, since I assume that's only calling the function when a show statement occurs, rather than every 0.05 seconds.
It is, yes. What ensure that there's effectively an image that is shown in place of the bogus one.
I presented the first option thinking about the question, "how can I make the call automatic", more than thinking about the context itself ; what was a really bad idea.
1. Why name
, rather than i
, which is the var used in the renpy.showing
& renpy.hide
statements?
Because I'm an idiot ?
I was thinking about the function declaration (
show( name, .... )
). So, I assume that my brain was thinking something like
if name in list_of_bogus_screen:
, while writing the loop.
Note that the "if" approach could also be interesting, but I'll come back to it after.
2. Why store.img_dict_mi
rather than directly referring to img_dict_mi
?
Because the branch 7.4.x made me become even more paranoid than I already was. Many times now addressing a variable inside a screen do not works without the
store.
prefix, so it became more or less an habit to put it everywhere.
But since you aren't assigning a value to it, Python would effectively fallback to the global, and so find the dict.
3. I have a limited understanding of how *args, **kwargs work, but it doesn't look like these args are modified after being pulled into the myShow function? So won't the renpy.show
statement display all the images present when myShow was initially called, including any which were hidden by renpy.hide
?
Effectively, nothing is changed. The goal of
*args, **kwargs
here is to catch, then pass, all the parameters without having to care about them, because they are insignificant.
You don't care what image Ren'Py will show, just that the bogus image aren't actually shown. Like the real "show" is called
after, this will works only if the image is replaced by another one.
Let's say that "bogus" is what you want to remove :
Python:
label whatever:
show whatever
# 'bogus' is not displayed, nothing to hide, 'whatever' is displayed.
[...]
hide whatever
show 'bogus'
# 'bogus' is not displayed YET, nothing to hide, 'bogus' is displayed.
[...]
show something
# 'bogus' is displayed, 'bogus' is hidden, 'something' is displayed.
[...]
hide something
show anotherthing
# 'bogus' is not displayed, nothing to hide, 'anotherthing' is displayed.
4. This is inside a python block, should it be renpy.config.show = myShow
?
No.
It's technical here.
config.
refer to the "config" store-like, where the configuration values are available, while
renpy.config
refer to the module named "config", where the configuration values are created and that handle the "config" store-like.
Practically, the main difference is that the store-like have some securities. You can't change some values once the game is started, you can't add new variables, and you can't delete a variable ; there's perhaps some other that I forgot.
You should always address the store-like, so use
config.whatever
, this will ensure that you don't make some mistakes.
renpy.config
is to use only for dirty moves,
when you know what you are doing.
With some of those changes it doesn't error out, but doesn't hide the orphaned images either.
This one is on you. I copied the code you gave, and it don't works:
if renpy.showing(i) == True and renpy.showing(img_dict_mi[i]) == True:
. It should be
or
, not
and
.
This works perfectly, I tested it:
Code:
def myShow( *args, **kwargs ):
for i in store.img_dict_mi:
if renpy.showing(i) == True or renpy.showing(img_dict_mi[i]) == True:
renpy.hide(img_dict_mi[i])
config.show = myShow
Now, all this being said, back to the "name" parameter...
The whole problem with this code, is that by default
show
n images are expected to be sprites. What mean that you can have:
Code:
label whatever:
show girl1_standing
[...]
show girl2_idle
[...]
hide girl1_standing
show girl1_afraid
[...]
hide girl1_afraid
[...]
show girl3_idle
[...]
hide girl3_idle
#hide girl2_idle
jump somewhere
label somewhere:
show background
[...]
The error is that "girl2_idle" is not removed at the end of the scene. But the fix would remove it when "girl1_afraid" is shown, what is way too early.
To correct this, you can rely on the name of the first image shown after the image should have been hidden ; here it's "background".
Python:
init python:
# Key is the image used as marker ; when this image is shown, there's possibly one
# that should have been hidden but wasn't.
img_dict_mi = {
# The value is a tuple, to let you use one maker for more than one image.
"background": ( "girl1_idle", ),
}
def myShow( name, *args, **kwargs ):
# The image to display is one of our markers.
if name in img_dict_mi:
# For all the image possibly still shown.
for i in img_dict_mi[name]:
# If it's shown, hide it.
if renpy.showing(i) == True: renpy.hide(i)
# And now display the image as asked.
renpy.show( name, *args, **kwargs )
config.show = myShow
Side note:
renpy.showing
works with image names, not with the image itself. Therefore your
renpy.showing(img_dict_mi[i])
was useless. It would have worked only in case of:
show "images/name.ext"
.