Subdirectories and audio in init blocks

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
Vict0r1994
Newbie
Posts: 19
Joined: Mon Apr 08, 2013 10:46 pm
Contact:

Subdirectories and audio in init blocks

#1 Post by Vict0r1994 »

Ok, my questions are pretty much what the title says. I consulted both the Ren'py wiki and manual to no avail, and my inquiries are as follows:
1. Can I define my audio files in an init block (pretty much like images) so that I could only write play music x instead of play music "insertlongname.mp3" within the script?
2. How can I reference subdirectories within the game folder without writing something like this - "D:/Imagini/renpy-6.14.1-sdk/Work_in_progress/game/Graphics/Backgrounds/House.png" - in every single image definition I have? Same thing goes for sounds and music which are placed now inside /game/Audio/Sounds and /game/Audio/Music. (now you probably know why I want to define the audio in init blocks too...)

Isn't there any way to avoid this tedious work? I don't want my game directory to look like a recycle bin with pngs, oggs and rpys in the same fies-ridden folder, but I don't want to write whole directories throughout the whole script either, so help will be very appreciated!

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Subdirectories and audio in init blocks

#2 Post by Asceai »

1. Can I define my audio files in an init block (pretty much like images) so that I could only write play music x instead of play music "insertlongname.mp3" within the script?
Yep.

Code: Select all

init python:
  x = "insertlongname.mp3"
or

Code: Select all

define x = "insertlongname.mp3"
For reference, this isn't defining an audio file so much as setting a variable to a string, but it will still work for play music x.
2. How can I reference subdirectories within the game folder without writing something like this - "D:/Imagini/renpy-6.14.1-sdk/Work_in_progress/game/Graphics/Backgrounds/House.png" - in every single image definition I have? Same thing goes for sounds and music which are placed now inside /game/Audio/Sounds and /game/Audio/Music. (now you probably know why I want to define the audio in init blocks too...)
You don't want to do that anyway. Your game will break on anyone else's computer. Give paths relative to the 'game' directory- that is, your House.png is:

Code: Select all

image House = "Graphics/Backgrounds/House.png"

User avatar
Taleweaver
Writing Maniac
Posts: 3428
Joined: Tue Nov 11, 2003 8:51 am
Completed: Metropolitan Blues, The Loyal Kinsman, Daemonophilia, The Dreaming, The Thirteenth Year, Adrift, Bionic Heart 2, Secrets of the Wolf, The Photographer
Projects: The Pilgrim's Path, Elspeth's Garden, Secret Adventure Game!
Organization: Tall Tales Productions
Location: Germany
Contact:

Re: Subdirectories and audio in init blocks

#3 Post by Taleweaver »

Ren'Py-specific questions go into the Ren'Py Questions forum.

Moving.
Scriptwriter and producer of Metropolitan Blues
Creator of The Loyal Kinsman
Scriptwriter and director of Daemonophilia
Scriptwriter and director of The Dreaming
Scriptwriter of Zenith Chronicles
Scriptwriter and director of The Thirteenth Year
Scriptwriter and director of Romance is Dead
Scriptwriter and producer of Adrift
More about me in my blog
"Adrift - Like Ever17, but without the Deus Ex Machina" - HigurashiKira

Vict0r1994
Newbie
Posts: 19
Joined: Mon Apr 08, 2013 10:46 pm
Contact:

Re: Subdirectories and audio in init blocks

#4 Post by Vict0r1994 »

Thanks a lot! I tried to do a relative-to-the-game-directory-pathway, but I always wrote it "game/Graphics/Backgrounds/House.png" instead of just "Graphics/Backgrounds/House.png" and it didn't work... Again, thanks for the help!
EDIT: Although the pathway works in its new form, I still can't define music! Whether I try it after "init python" or before in the ways suggested above, ren'py crashes and says "IO Error: couldn't find file [defined-name]"

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Subdirectories and audio in init blocks

#5 Post by Asceai »

Vict0r1994 wrote:EDIT: Although the pathway works in its new form, I still can't define music! Whether I try it after "init python" or before in the ways suggested above, ren'py crashes and says "IO Error: couldn't find file [defined-name]"
Post code, both the code where you define it and the code where you play it.

Vict0r1994
Newbie
Posts: 19
Joined: Mon Apr 08, 2013 10:46 pm
Contact:

Re: Subdirectories and audio in init blocks

#6 Post by Vict0r1994 »

The code where I define it:

Code: Select all

define alarm_clock = "Audio/Sounds/alarm_clock.mp3"
The code where I play it:

Code: Select all

play sound "alarm_clock"
I double-checked the name and extension of the file and it is indeed "alarm_clock.mp3". What am I doing wrong?

Vict0r1994
Newbie
Posts: 19
Joined: Mon Apr 08, 2013 10:46 pm
Contact:

Re: Subdirectories and audio in init blocks

#7 Post by Vict0r1994 »

No matter. Found the mistake. I shouldn't have put commas where I played it. Thanks again!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Ocelot