DynamicImage translates path the wrong way

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
DrVoom
Newbie
Posts: 5
Joined: Sat May 29, 2021 7:54 am
Contact:

DynamicImage translates path the wrong way

#1 Post by DrVoom » Sun Nov 14, 2021 3:00 pm

I have a python variable that leads to an image.

Code: Select all

$ img = "D:\dir\image.jpg"
when i display the variable with

Code: Select all

e "[img]" 
all is looking fine - i get D:\dir\image.jpg

when i set it as an image with

Code: Select all

 image profile = "[img]"
and show it with

Code: Select all

 show profile 
i get
"Exception: DynamicImage u'[img]': could not find image. (u'D:\\dir\\image.jpg')

There are double \\'s in the Exception Statement. The image exists at that place. Any hints what newbie error i am making? Thanks!

rayminator
Miko-Class Veteran
Posts: 754
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: DynamicImage translates path the wrong way

#2 Post by rayminator » Sun Nov 14, 2021 3:07 pm

it should look like this

Code: Select all

$ img = "images\dir\image.jpg"
you are including you hard driver directory in the code that other players don't have that drive letter

drKlauz
Veteran
Posts: 237
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: DynamicImage translates path the wrong way

#3 Post by drKlauz » Sun Nov 14, 2021 4:26 pm

Avoid using \ in paths, it is escape character in python. It is not obvious from your example, but if you use

Code: Select all

img = "D:\dir\bg.jpg"
print(img)
it will print "D:\dig.jpg", because \b is converted to backspace character. In this case img will be "D:\\dir\x08g.jpg"
Use / instead.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

Post Reply

Who is online

Users browsing this forum: Google [Bot]