Issue setting image directory with variable

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
Spallidshorse
Newbie
Posts: 12
Joined: Thu Dec 08, 2016 3:13 pm
Contact:

Issue setting image directory with variable

#1 Post by Spallidshorse »

Hello.

I've got a character status screen that shows stats and then an image of the character.

What I'm currently attempting to do is use a dict (posed) and variable (displayed_character) to generate sub-images by pointing renpy to a specific sub-directories within the image directory depending on the character or values in the dict. The sub-images are then passed to LiveComposite as layers of the final image. The sub-images are all the same dimension to avoid having to fiddle with a bunch of position values if we need to change one sort of sub-images (ie, if we need to change all the eyes).

Whenever image tries to find the directory variable, however, I get this error:

Exception: In DynamicImage u'[directory]/base.png': Could not find substitution 'directory'.

My guess is that this has something to do with how/when images are created, but I can't figure it out.

Any solutions? Is this just a no-go?

Code: Select all


init - 1 python:
	$define posed = {
	"position": "foo",
	"eyes": "bar"
	}
	
	$displayed_character = "baz"
	$position = posed["position"]
	$directory = "[position]/[displayed_character]"
	$eyes = posed["eyes"]

image base = "[directory]/base.png"
image eyes = Animation("[directory]/[eyes].png", 2.0, "[directory]/eyes shut.png", 0.2)

image status_screen_character_display = LiveComposite(
    (800, 600),
    (0,0), "base",
    (0,0), "eyes"
    )
    
   screen status():
   
   	add "status_screen_character_display"

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Issue setting image directory with variable

#2 Post by Remix »

lose the $ signs inside the python block... you only ever need them for simple one liners in Ren'py blocks...

Code: Select all

init -1 python:
    posed = {
	"position": "foo",
	"eyes": "bar"
	}
	
    displayed_character = "baz"
    position = posed["position"]
    directory = "[position]/[displayed_character]"
    eyes = posed["eyes"]
Frameworks & Scriptlets:

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Issue setting image directory with variable

#3 Post by Remix »

That does appear to define a lot of variable values outside of where you really need them though. It could well be easier passing them as parameters into a screen and having internal logic within the screen build the references

Untested code - maybe just add a few text "[directory]/[eyes].png" bits too to help debug

Code: Select all

screen show_char( position="foo", eyes="bar", char="baz" ):
    $ directory = "/".join( [ position, char ] )
    fixed:
        add LiveComposite(
            (800, 600),
            (0,0), "[directory]/base.png",
            (0,0), Animation("[directory]/[eyes].png", 2.0, "[directory]/eyes shut.png", 0.2) )
Frameworks & Scriptlets:

Spallidshorse
Newbie
Posts: 12
Joined: Thu Dec 08, 2016 3:13 pm
Contact:

Re: Issue setting image directory with variable

#4 Post by Spallidshorse »

Remix wrote: Wed Nov 15, 2017 2:41 pm lose the $ signs inside the python block... you only ever need them for simple one liners in Ren'py blocks...
Whoops! I was fiddling with it right before posting and forgot I'd stuck the variables in a python block. Thanks/sorry!
Remix wrote: Wed Nov 15, 2017 3:07 pm That does appear to define a lot of variable values outside of where you really need them though. It could well be easier passing them as parameters into a screen and having internal logic within the screen build the references
This is closer to what I was thinking of doing. I'm just doing the most rudimentary step before I start messing with the screen and seeing what I can stick in functions/classes.

That said, removing the $ signs didn't fix the issue. I think the problem I'm running into is that Image() doesn't permit interpolating variables in the image location string, and implementing it as image bar = "[bar]" makes renpy think I'm trying to call DynamicImage which means "[bar]" is no longer read as pointing to a file but, I think, another image (if I'm understanding the purpose and function of DynamicImage).

I think I may just have to figure out ConditionSwitch

Errilhl
Regular
Posts: 164
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Deviantart: studioerrilhl
Github: studioerrilhl
Contact:

Re: Issue setting image directory with variable

#5 Post by Errilhl »

Can't you do a simple call, like this:

Code: Select all

    add LiveComposite(
            (800, 600),
            (0,0), ""+str(directory)+"/base.png",
            (0,0), Animation(""+str(directory)+"/"+str(eyes)+".png", 2.0, ""+str(directory)+"/eyes shut.png", 0.2) )
Not entirely sure you need the str() wrapper, I've just found that it sometimes helps when Renpy balks at whatever I try to concat.
Currently working on: Image

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

Re: Issue setting image directory with variable

#6 Post by henvu50 »

concatenate the variables 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)

Post Reply

Who is online

Users browsing this forum: BBN_VN