DynamicImage error

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
Maou Zenigame
Regular
Posts: 66
Joined: Thu Nov 09, 2017 3:09 am
Contact:

DynamicImage error

#1 Post by Maou Zenigame »

Since several of the characters in my game have multiple outfits, I have all their sprites in a standardized naming format and used the DynamicImage function to swap them out with a variable.

So as an example, the character definitions are done like this:

Code: Select all

image mari cross1 = "Full/[mari_wardrobe]_armcross_1.png"
where the "mari_wardrobe" bit is the part that changes in the sprites' filenames.

This works like a charm, but if the player tries to exit to the main menu when one of these characters is on screen then this error pops up:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
Exception: In DynamicImage u'Close/[mari_wardrobe]_default_close_1.png': Could not find substitution 'mari_wardrobe'.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\ast.py", line 862, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\python.py", line 1912, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
    python hide:
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
    ui.interact()
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 2649, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 3033, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 513, in visit_all
    callback(self)
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\core.py", line 3033, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\image.py", line 726, in per_interact
    self.find_target()
  File "C:\Users\Zenigame\Desktop\renpy-6.99.1-sdk\renpy\display\image.py", line 618, in find_target
    raise Exception("In DynamicImage %r: Could not find substitution '%s'." % (self.name, unicode(ke.args[0])))
Exception: In DynamicImage u'Close/[mari_wardrobe]_default_close_1.png': Could not find substitution 'mari_wardrobe'.
Does anyone out there know how to get this to stop happening?

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: DynamicImage error

#2 Post by kivik »

The error is saying that the variable doesn't exist and it can't do the text interpolation - do you have a function or python code that unsets the variable on your menu somehow?

Maou Zenigame
Regular
Posts: 66
Joined: Thu Nov 09, 2017 3:09 am
Contact:

Re: DynamicImage error

#3 Post by Maou Zenigame »

I set all of the "wardrobe" values at the start of the game and don't do anything to unset the values afterwards, only change them when needed.

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: DynamicImage error

#4 Post by henvu50 »

concatenate them to fix it. quotes and + like this:
see the variable? they're not within quotes.

Code: Select all

screen test3():
    for stuff1, stuff2 in thisobject:
       imagebutton:
         idle "1/2/" + stuff1 + "_" + stuff2 + "_idle.png"
         hover "1/2/" + stuff1 + "_" + stuff2 + "_hover.png"
(i know the post is old, but it came up in google, just wanted the solution to be there)

meagkhan
Newbie
Posts: 1
Joined: Tue Jan 01, 2013 6:26 pm
Contact:

Re: DynamicImage error

#5 Post by meagkhan »

henvu50 wrote: Mon Jun 14, 2021 9:59 am concatenate them to fix it. quotes and + like this:
see the variable? they're not within quotes.

Code: Select all

screen test3():
    for stuff1, stuff2 in thisobject:
       imagebutton:
         idle "1/2/" + stuff1 + "_" + stuff2 + "_idle.png"
         hover "1/2/" + stuff1 + "_" + stuff2 + "_hover.png"
(i know the post is old, but it came up in google, just wanted the solution to be there)
I just want to say thank you for posting this solution-- you've saved me from hours of tearing my hair out over something so simple!

Post Reply

Who is online

Users browsing this forum: Google [Bot]