Page 1 of 1

Image in folder not found

Posted: Thu Jun 29, 2017 5:50 pm
by nuby
I have ren'py set to show the file mc_happy as mc h right before the first line of dialogue. However, no matter what I try, I end up with "could not find file 'mc_happy.png". I know it's in the folder. I have tried basically everything and the closest i've gotten is having no character pop up at all while having the dialogue going.

Code: Select all

# The script of the game goes in this file.
# game resolution - 1280x720

# Declare characters used by this game. The color argument colorizes the
# name of the character.

define e = Character("Eileen") # delete later
define mc = Character("Me")

image mc h = "mc_happy.png"

# The game starts here.

label start:

    scene bg room

    show mc h

    # These display lines of dialogue.

    mc "Here it was."
    
    mc "My first day at my new school."
    
    # This ends the game.

    return
I know it's pretty generic and there's not much but this is my first project so I'd really appreciate the help.

Re: Image in folder not found

Posted: Thu Jun 29, 2017 6:28 pm
by Imperf3kt
Do you have hide file extensions on? It is default in Windows. You might see mc_happy.png but could have mc_happy.png.png

Re: Image in folder not found

Posted: Thu Jun 29, 2017 6:30 pm
by chocoberrie
Two things:

1) Your image definitions aren't in an init block.
2) Did you check the file paths for the images?

Here is an example:

Code: Select all

init:   
    image bg street = "BGs/bg_street.jpg"
    image bg school hall = "BGs/school_hall.jpg"
    image bg school grounds = "BGs/school_grounds.jpg"

label start:
Each of these images is in a folder called "BGs," which is within the folder called "game" (the default folder where all of the Ren'Py files are).

Re: Image in folder not found

Posted: Thu Jun 29, 2017 6:51 pm
by nuby
chocoberrie wrote:Two things:

1) Your image definitions aren't in an init block.
2) Did you check the file paths for the images?

Here is an example:

Code: Select all

init:   
    image bg street = "BGs/bg_street.jpg"
    image bg school hall = "BGs/school_hall.jpg"
    image bg school grounds = "BGs/school_grounds.jpg"

label start:
Each of these images is in a folder called "BGs," which is within the folder called "game" (the default folder where all of the Ren'Py files are).
So would the correct way to do this be..

Code: Select all

init:
    image mc h = "images/mc_happy.png"

# The game starts here.

label start:
? This still has the same result as before. Also, I do not see the BGs folder in my game folder. Should I manually add this? Also, I did not manually add .png to the end, I assume Windows did and then hid the extension?

Re: Image in folder not found

Posted: Thu Jun 29, 2017 7:19 pm
by chocoberrie
No no, I mean if your images are in a subfolder, make sure to include the subfolder in the image definition. The "BGs" folder is an example, that is what I did for my images. I made a folder called "BGs" within the "game" folder. In the "BGs" folder, I put the image files I defined in the example code. The file path is indicated for each image, as well as the file extension.

Because the images are in the "BGs" folder, I have:
image [image tag here] = "folder name here/file name.extension"
(*Note: Don't include the brackets shown above.)

The reason why I have subfolders is because it's easier to organize images. Putting them all in the "game" folder with the script files makes organization difficult.

See the screenshots below:

Re: Image in folder not found

Posted: Thu Jun 29, 2017 7:37 pm
by nuby
chocoberrie wrote:No no, I mean if your images are in a subfolder, make sure to include the subfolder in the image definition. The "BGs" folder is an example, that is what I did for my images. I made a folder called "BGs" within the "game" folder. In the "BGs" folder, I put the image files I defined in the example code. The file path is indicated for each image, as well as the file extension.

Because the images are in the "BGs" folder, I have:
image [image tag here] = folder name here/file name.extension
(*Note: Don't include the brackets shown above.)

The reason why I have subfolders is because it's easier to organize images. Putting them all in the "game" folder with the script files makes organization difficult.

See the screenshots below:
Oh! My mistake. I moved the sprites from images to my own Sprites folder and changed the code accordingly

Code: Select all

init:
    image mc h = Sprites/mc_happy.png

# The game starts here.

label start:
I'm afraid now instead of "image not found" I'm getting

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 20, in script
    image mc h = Sprites/mc_happy.png
  File "game/script.rpy", line 20, in <module>
    image mc h = Sprites/mc_happy.png
NameError: name 'Sprites' is not defined
This seems like a simple enough fix but I regret to say I'm at a loss again. Hopefully when this is done it will be a one time problem, so I apologize if I'm wasting your time.

Re: Image in folder not found

Posted: Thu Jun 29, 2017 7:38 pm
by chocoberrie
You need quotation marks! Sorry, it was my mistake; I did not add those.

Try this:

Code: Select all

init:
    image mc h = "Sprites/mc_happy.png"

# The game starts here.

label start:

Re: Image in folder not found

Posted: Thu Jun 29, 2017 7:52 pm
by nuby
Back to "can't find" w/ quotes.. darn. What should I try now?

Re: Image in folder not found

Posted: Thu Jun 29, 2017 9:04 pm
by Imperf3kt
Go back to the very basics.
Renpy can auto define your images.
If you have show "bob.png" and bob.png is in the images folder, it will work.

If you wish to use tags, define them before the start label in your script or place them in an init block as shown by chocoberrie.

Code: Select all

image bob happy = "bob_happy.png"

label start:
    show bob happy
You must have an image called "bob_happy.png" in the images folder for this to work.

Re: Image in folder not found

Posted: Thu Jun 29, 2017 10:34 pm
by nuby
I've solved the problem! I don't really know what the problem was OR how I fixed it.. but thank you guys for your help! :)

Re: Image in folder not found

Posted: Fri Jun 30, 2017 12:04 am
by trooper6
image definitions don't need to be in an init block.

Re: Image in folder not found

Posted: Fri Jun 30, 2017 10:17 am
by chocoberrie
trooper6 wrote:image definitions don't need to be in an init block.
Oh! I didn't know that. Thanks for the clarification; I'll check the documentation.

Re: Image in folder not found

Posted: Fri Jun 30, 2017 3:49 pm
by trooper6
image definitions, character definitions, variable definitions using define and default: none of those need to be in init blocks.

Re: Image in folder not found

Posted: Fri Jun 30, 2017 5:24 pm
by Imperf3kt
trooper6 wrote:image definitions, character definitions, variable definitions using define and default: none of those need to be in init blocks.
But they do need to be outside of any labels. Keep that part in mind.

One exception though. If you are using legacy mode and you use Leon's CG gallery code, you do infact need to duplicate your image definitions inside an init block otherwise it won't work.