Page 1 of 1

DynamicImage error

Posted: Sun Jun 17, 2018 3:22 pm
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?

Re: DynamicImage error

Posted: Sun Jun 17, 2018 4:22 pm
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?

Re: DynamicImage error

Posted: Sun Jun 17, 2018 5:02 pm
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.

Re: DynamicImage error

Posted: Mon Jun 14, 2021 9:59 am
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)

Re: DynamicImage error

Posted: Wed Sep 27, 2023 4:25 pm
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!