Ren'Py "Basic Functions" Coding Template or Example?

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
I'm at the point in my VN development when I'll soon have to start Ren'Py coding. Never done Ren'Py before or any sort of game whatsoever, though I have some coding experience/familiarity in my life history.

What I'm thinking would be helpful is a single Ren'Py script sample... sort of a mini-tutorial, but all in a single piece of code, that lays out basic, common tasks one after the other, with enough comment to explain the necessary functions, variables, syntax and values in each example. Note that the code wouldn't be intended to actually be functional - just sort of a clearing house of basic code snippets with comments. Hopefully I'm describing this clearly.

Does such a thing exist?
 
  • Like
Reactions: Saint Blackmoor

Count Morado

Devoted Member
Respected User
Jan 21, 2022
8,332
16,042
And the Quickstart tutorial on the official site doesn't fit the bill for you?

Or you could look at all the commands:
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,959
16,193
And the Quickstart tutorial on the official site doesn't fit the bill for you?
Or the two demonstration games (tutorial and the question) that come with the SDK.

And of course the hundreds threads, and few tutorials, available here.
 
  • Yay, update!
Reactions: Count Morado

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
And the Quickstart tutorial on the official site doesn't fit the bill for you?

Or you could look at all the commands:
TBH I have some weird problem on my PC that I've wasted literally hours trying to fix (and finally given up on) that renders certain web fonts almost entirely unreadable. Something having to do with Helvetica or Helvetica Neue. I've deleted fonts, added them, restarted, etc... ad nauseum... to no avail. In any case, virtually the entire Renpy site uses that font. I simply can't read it. I suppose I could start copying blocks of text from the webpages and create a huge Word document, changing the font to something readable, but then I'd have none of the linking functions of the site. I'm just looking for a single, relatively minimal document or block of "code" that provides the most common operations with explanatory comments. Almost like a cheat sheet. If I missed some post that provides this I apologize, but I figured just asking might be faster than spending an hour or more searching through forums here. I have done some searching here and so far found nothing that fits the bill.
 
Last edited:

TessaXYZ

Active Member
Game Developer
Mar 24, 2020
686
1,498
TBH I have some weird problem on my PC that I've wasted literally hours trying to fix (and finally given up on) that renders certain web fonts almost entirely unreadable. Something having to do with Helvetica or Helvetica Neue. I've deleted fonts, added them, restarted, etc... ad nauseum... to no avail. In any case, virtually the entire Renpy site uses that font. I simply can't read it. I suppose I could start copying blocks of text from the webpages and create a huge Word document, changing the font to something readable, but then I'd have none of the linking functions of the site. I'm just looking for a single, relatively minimal document or block of "code" that provides the most common operations with explanatory comments. Almost like a cheat sheet. If I missed some post that provides this I apologize, but I figured just asking might be faster than spending an hour or more searching through forums here. I have done some searching here and so far found nothing that fits the bill.
The examples that come packaged with Renpy do exactly this.
 
  • Like
Reactions: Mikethe3DGuy

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
The examples that come packaged with Renpy do exactly this.
Thanks. It's been about a year since I installed Ren'Py and have barely even given it a glance since then, while burying my head in creating content. Could be they're closer to what I need than I recall. I opened their webpage and was immediately reminded of the font problems, then did some searching here and figured I'd ask for more help. I appreciate your response.

Sidenote: I'm intrigued by the game/Patreon links in your signature and will check them out!
 
  • Heart
Reactions: TessaXYZ

GamesMtP

Well-Known Member
Game Developer
Jul 2, 2017
1,268
3,368
I'm at the point in my VN development when I'll soon have to start Ren'Py coding. Never done Ren'Py before or any sort of game whatsoever, though I have some coding experience/familiarity in my life history.

What I'm thinking would be helpful is a single Ren'Py script sample... sort of a mini-tutorial, but all in a single piece of code, that lays out basic, common tasks one after the other, with enough comment to explain the necessary functions, variables, syntax and values in each example. Note that the code wouldn't be intended to actually be functional - just sort of a clearing house of basic code snippets with comments. Hopefully I'm describing this clearly.

Does such a thing exist?
When you've checked some examples, download some games that does roughly what you want to do and unren them and see how they did it. (Just don't outright copy/steal code, that's rude! ;) )

There's also lots of helpful threads of do's and dont's in this very forum. I'm not much of a programmer but am managing to put a VN together, 100% thanks to F95zone!
 
  • Like
Reactions: Mikethe3DGuy

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
When you've checked some examples, download some games that does roughly what you want to do and unren them and see how they did it. (Just don't outright copy/steal code, that's rude! ;) )

There's also lots of helpful threads of do's and dont's in this very forum. I'm not much of a programmer but am managing to put a VN together, 100% thanks to F95zone!
Thanks! That's exactly why I'm here. Fortunately, the coding required for my game should be less complex than most, though possibly lengthier due to the fact that I'm using 4 audio tracks and quite a few sound files.
 

GamesMtP

Well-Known Member
Game Developer
Jul 2, 2017
1,268
3,368
Thanks! That's exactly why I'm here. Fortunately, the coding required for my game should be less complex than most, though possibly lengthier due to the fact that I'm using 4 audio tracks and quite a few sound files.
In that case I have a music tip for you: Use two music channels so you can tune one out and start tuning the other in. That way you wont have any abrupt stops.
renpy.music.register_channel("music2", "music") <- like that in options.rpy, I don't remember if it's default or if I added it.

Then to start/stop, alternate channels so music2 follows music
play music [ "song.ogg" ] fadein 3.0
stop music fadeout 3.0
play music2 [ "othersong.ogg" ] fadein 3.0

And so on. Fadein/fadeout delay can be changed as you please. To throw in sounds without interrupting the music:
play audio "soundeffect.ogg" noloop

Nothing new that's not in the manual anyway, I guess. Cheers.
 
  • Like
Reactions: Mikethe3DGuy

TessaXYZ

Active Member
Game Developer
Mar 24, 2020
686
1,498
Thanks! That's exactly why I'm here. Fortunately, the coding required for my game should be less complex than most, though possibly lengthier due to the fact that I'm using 4 audio tracks and quite a few sound files.
Shouldn't make a huge difference. I'm using 11 audio channels, but it doesn't really make an enormous impact. Just make sure that if you're mixing between channels, you account for what happens to the channel mix when a player scrolls backwards.
 

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
Shouldn't make a huge difference. I'm using 11 audio channels, but it doesn't really make an enormous impact. Just make sure that if you're mixing between channels, you account for what happens to the channel mix when a player scrolls backwards.
Well, what I mean is that with multiple tracks you need to type out more code, right? Don't I have to link voice and sfx files to play at a particular time to match a still image and dialogue? But ELEVEN? Holy crap.
 

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
In that case I have a music tip for you: Use two music channels so you can tune one out and start tuning the other in. That way you wont have any abrupt stops.
renpy.music.register_channel("music2", "music") <- like that in options.rpy, I don't remember if it's default or if I added it.

Then to start/stop, alternate channels so music2 follows music
play music [ "song.ogg" ] fadein 3.0
stop music fadeout 3.0
play music2 [ "othersong.ogg" ] fadein 3.0

And so on. Fadein/fadeout delay can be changed as you please. To throw in sounds without interrupting the music:
play audio "soundeffect.ogg" noloop

Nothing new that's not in the manual anyway, I guess. Cheers.
That's a good idea! Though I'll have to check whether I have any music tracks that are followed immediately by another one when they end. It's possible I don't.
 

TessaXYZ

Active Member
Game Developer
Mar 24, 2020
686
1,498
Well, what I mean is that with multiple tracks you need to type out more code, right? Don't I have to link voice and sfx files to play at a particular time to match a still image and dialogue? But ELEVEN? Holy crap.
Sure, but ultimately it's a very small part of the bigger effort and is pretty trivial compared to everything else.

One thing I'll mention as a general design rule, since you mentioned in your last comment that you don't know if you have any music tracks that are followed by another one: Quality games = no silence. There should always be something playing. Music, soundscapes, or both music and soundscapes. If you're going to include sound in your game, fading into silence is a no-no.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,959
16,193
In any case, virtually the entire Renpy site uses that font.
Absolutely not.

Ren'Py site have two font declarations, one for the text, defined as sans-serif, and the other, for the code example, defined as Menlo,Monaco,Consolas,"Courier New",monospace, in that order of priority. It's your browser that use Helvetica, not the site.
Site note: the whole documentation come with the SDK, and so is available on your hard drive.


I'm just looking for a single, relatively minimal document or block of "code" that provides the most common operations with explanatory comments.
And TessaXYZ and I gave you the answer. The SDK come with two complete demonstration games doing this.


I have done some searching here and so far found nothing that fits the bill.
Not even the two guides wrote by 79flavors , here and there ?
 

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
Sure, but ultimately it's a very small part of the bigger effort and is pretty trivial compared to everything else.

One thing I'll mention as a general design rule, since you mentioned in your last comment that you don't know if you have any music tracks that are followed by another one: Quality games = no silence. There should always be something playing. Music, soundscapes, or both music and soundscapes. If you're going to include sound in your game, fading into silence is a no-no.
That's interesting, because when you read information about film scoring, they tell budding music supervisors and film composers that the number one rookie mistake is to try and fill every scene with music. They recommend being more sparing with it. Should games (well, mine is a VN, so closer to a movie than a standard "video game") be any different?

I just reviewed my sound plan and calculated that just over 60% of my scenes include music. By "scenes", I mean static images displayed.
 
Last edited:

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
Absolutely not.

Ren'Py site have two font declarations, one for the text, defined as sans-serif, and the other, for the code example, defined as Menlo,Monaco,Consolas,"Courier New",monospace, in that order of priority. It's your browser that use Helvetica, not the site.
Site note: the whole documentation come with the SDK, and so is available on your hard drive.




And TessaXYZ and I gave you the answer. The SDK come with two complete demonstration games doing this.




Not even the two guides wrote by 79flavors , here and there ?
I always thought that websites determined the font used on their own sites, but then again I'm not a web designer. In that case is there some way to force my browser (Chrome) to use a different font?

79flavors actually DM'ed me shortly after reading this OP and linked his unfinished PDF, which will probably be very helpful! Oddly, I didn't get the sense I was annoying him by being a newbie asking for advice or help.
 
Last edited:

TessaXYZ

Active Member
Game Developer
Mar 24, 2020
686
1,498
That's interesting, because when you read information about film scoring, they tell budding music supervisors and film composers that the number one rookie mistake is to try and fill every scene with music. They recommend being more sparing with it. Should games (well, mine is a VN, so closer to a movie than a standard "video game") be any different?

I just reviewed my sound plan and calculated that just over 60% of my scenes include music. By "scenes", I mean static images displayed.
I didn't say always have "music". I said "music" or "soundscapes" or both music and soundscapes. Movies never have silence, they always have something audible. Most VN's here that include music go from perfect silence to blaring music. THAT is the no-no, in any medium.

Edit: E.g. if your VN in a city? Well then you should have the background hum of a city. Is it in a forest? Wind, birds, rustling leaves. You get the drift.
 
  • Like
Reactions: Mikethe3DGuy

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
I didn't say always have "music". I said "music" or "soundscapes" or both music and soundscapes. Movies never have silence, they always have something audible. Most VN's here that include music go from perfect silence to blaring music. THAT is the no-no, in any medium.

Edit: E.g. if your VN in a city? Well then you should have the background hum of a city. Is it in a forest? Wind, birds, rustling leaves. You get the drift.
Wasn't familiar with the term "soundscape" and thought it meant something similar to music, but after looking it up, it just seems to be ambient background noise to match the environment. And yeah: I have those all over the place. Office sounds, freeway sounds, city street noises, morning birds chirping, etc. Sometimes with music, sometimes by themselves. Are there scenes with no ambient noise, and no music? Good question - there are probably some. So: good point! I'll look through and may have to fill in some ambient tracks here and there, because I agree.
 
  • Like
Reactions: TessaXYZ

Mikethe3DGuy

Member
Game Developer
Mar 14, 2019
233
449
In that case I have a music tip for you: Use two music channels so you can tune one out and start tuning the other in. That way you wont have any abrupt stops.
renpy.music.register_channel("music2", "music") <- like that in options.rpy, I don't remember if it's default or if I added it.

Then to start/stop, alternate channels so music2 follows music
play music [ "song.ogg" ] fadein 3.0
stop music fadeout 3.0
play music2 [ "othersong.ogg" ] fadein 3.0

And so on. Fadein/fadeout delay can be changed as you please. To throw in sounds without interrupting the music:
play audio "soundeffect.ogg" noloop

Nothing new that's not in the manual anyway, I guess. Cheers.
After reviewing this again I realized I'm not completely clear on why the second music track is needed. Is it because you have to trigger changes in music based on the player hitting the spacebar to advance, and therefore the "outgoing" song would necessarily just end abruptly when that happens, followed by a fadein of the "incoming" song? So you fade out song.ogg after the player advances wile fading in othersong.ogg at the same time (or just after)?

Sorry if that doesn't make sense. Feel free to tell me to learn more of the basics first if you think it will become clear to me as I learn. I don't want to waste your time.
 

GamesMtP

Well-Known Member
Game Developer
Jul 2, 2017
1,268
3,368
After reviewing this again I realized I'm not completely clear on why the second music track is needed. Is it because you have to trigger changes in music based on the player hitting the spacebar to advance, and therefore the "outgoing" song would necessarily just end abruptly when that happens, followed by a fadein of the "incoming" song? So you fade out song.ogg after the player advances wile fading in othersong.ogg at the same time (or just after)?

Sorry if that doesn't make sense. Feel free to tell me to learn more of the basics first if you think it will become clear to me as I learn. I don't want to waste your time.
It's not strictly needed, it just makes changing song much smoother listening experience for the player when a song isn't cut abruptly. Typically you don't want a lot of silence between songs. Players will also advance between screens and very different paces.

Then again, your game, you decide.
 
  • Like
Reactions: Mikethe3DGuy