Reply to topic  [ 1 post ] 
 Coding with Renpy, Part 1 
Author Message
Level 39
Level 39
User avatar

Cash on hand:
2,187.55

Bank:
5,250.50
Posts: 21063
Joined: Sat Feb 14, 2009 11:44 pm
Group: Sysop
Post Coding with Renpy, Part 1
OR

A crude log of my experiments with Renpy.

Getting shits set up.

Level: Absolute beginner.

What we're gonna do: We're going to create a simple visual novel using Ren'Py, an engine for creating visual novels, complete with dialogue, choices, graphics, and sounds.

At the end of this tutorial series, you'll have learned how to create a visual novel with Ren'Py, and you'll have a finished game that can be sent to other people.

Skills that are absolutely needed to start off:

- Basic comprehension of ENGLISH MOTHERFUCKER, DO YOU SPEAK IT?!

- Downloading stuff.

Skills that will almost certainly come in handy as we go:

- Being able to draw people and scenery

- Being able to tell a story

Well, then; let's begin...

Step 0: A short (riiight) introduction to visual novels

Visual novels are, in short, kind of a mix between novels and video games. If you’ve ever tried a "Choose Your Own Adventure"-book, you’ll understand the concept pretty quickly.

They’re not exactly a video game in the classical sense, in that you can’t control most of the things that happen. Instead, you follow the story as it goes along. However, you’ll get several chances to interact, like in this scene:

Image
I still want to play Katawa Shoujo. ;_; Someone help me with this stupid corrupted file.

Depending on your actions, the story is affected in different ways; the game might even end differently. BAD END GET.

If you're still unsure about what a visual novel is, just follow the tutorial. You’ll get to try out a short visual novel for yourself.

To make our visual novel, we’re going to use the engine Ren’Py, which allows us to create a visual novel without having to code everything.

Before starting, you must have...

- The Renpy engine. Get it here

- A decent code editor. I use SCITE/JEDIT. You can use notepad++ if that's how you roll.

Step 1: Getting everything we need

The only thing you really need for now is Ren’Py itself. Again, you can find it here.

When you’ve downloaded the program, start it. It will ask you for a directory. You can ignore this, however; if you click "OK" straight away, Ren’Py will appear in the same directory that you downloaded the .exe to.

If you downloaded the .zip instead, just extract it with your favorite unarchiver.

If you use Linux; download "renpy-6.9.0-sdk.tar.bz2" instead. Extract it by using this command in the terminal:

Code:
tar -jxvf renpy-6.9.0-sdk.tar.bz2


You might also want to check if you have an updated version of Java. The games can be run without it, but the included editor(jEdit) won't run without Java.

Step 2: Playing your first visual novel

Open up the folder, and run the Ren’Py launcher. On Windows, this will be renpy.exe. If you're running Linux, it'll be renpy.sh.

You'll see something like this... maybe:

Image
Yes, that's the Ren'Py launcher

Choose "Select Project", pick "the question", and finally "Launch".

You'll see the game "The Question", a small visual novel designed for people new to them. I recommend playing it to get a feel for what visual novels are, and how they'll play.

(Don’t worry, you don’t have to make yaranaika games... yet *insert sinister laugh here*)

When you're finished playing it, and ready to create stuff, exit the game. You'll be back at the Ren'Py launcher. This time, pick "New Project", and then "Template". Give the project a name; I'll call it "The Quarter". Finally, pick a theme for the project. It doesn’t matter which.

After a few moments you should be returned to the launcher again, with the new project selected. Click "Edit Script" to get started.

The editor, jEdit (you did set it as your standard editor, right? You didn't? Oh FFS set it in the preferences, in the launcher!), will now start, with the file "script.rpy" open. Delete the placeholder data, and put this in it instead:

Code:
label start:
    "Me" "I wish I had some money..."
    "Me" "It's so damn hot."
    "Me" "I’d rather take the bus instead of walking there."
    "Me" "...What’s that?"
    "I saw something shiny on the street."
    "I picked it up."
    "It was 50 bucks! (and some gum)"
    "That cheered me up... "
    "Girl" "Excuse me, but have you seen any any around here?"
    "Girl" "*sigh* I can’t find my money..."
    return


Save it, go back to the launcher, and press "Launch".

Yay! You now have created your first visual novel! Granted, it lacks certain things, like graphics, PPPOOOOOORRRRNNNS!, sound and an actual plot, but it’s a start, right?

Step 3: Understanding the code, or ENGLISH MOTHERFUCKER! DO YOU SPEAK IT!

In the last step, you’ve somehow created your first visual novel (or maybe you didn't); now it’s time to see how it works.

First, we have the line:

Code:
label start:


This is required for every game programmed in Ren’Py; it’s where the game starts.

Note:
A bit on indentation: You might have noticed that all the lines, except for this one, have 4 spaces in front. If you’ve used Python, you’ll know this as indentation. This is how Python, and therefore Ren’Py, groups statements in the code. Don’t worry: jEdit handles this, so you don’t need to worry for now.

Now, on to the second line:

Code:
"Me" "I wish I had some money..."


This is what’s going to make up a good part of the novel; dialogue. This line will show up as this in the game:

As you can see, the first quote defines the name of the person speaking, and the second quote is what’s going to be said.

Since the next few lines are pretty similar, let’s just skip ahead to the fifth line:

Code:
"I saw something shiny on the street."


This is narration: dialogue without anyone speaking. There are some situations where narration is best to use, such as describing thoughts, emotions or actions.

Now that we know what those lines do, there’s only line that hasn’t been covered yet;

Code:
return


A return statement ends the game. While the game works fine without one, it’s a good habit to have one at the end of the game.

Now that we know what each line does, it's time to move on to...

Step 4: Adding characters

Code:
    "Catgirl" "Nyan~"


This is an example of what we've been using to create the dialogue. This method works pretty well. However, there's a problem with it:

What would happen if we, for some inexplicable reason, decided to name the Catgirl "Angry Catgirl with a Big Gun"?

Two things would happen.

The code would look something like this:

Code:
    "Angry Catgirl with a Big Gun" "You there, where did you hide my watch!?"
    "Angry Catgirl with a Big Gun" "Tell me or else I pewpewpew you!"
    "Angry Catgirl with a Big Gun" "..."
    "Angry Catgirl with a Big Gun" "Oh yeah, it's up my snatch. LOL"


and the coder would probably look something like this after a while:
Image
Coder: I coulda been a contenda! I coulda been a somebody!

Long character names are a bane for any typist.

Obviously, this is a problem.

-

The best way to solve this is to use characters: by predefining the names of the characters in the story, we can cut down the size of the code considerably.

To define characters, we put something like this in the beginning of the code:

Code:
init:
    $ y = Character("Yotsuba")



The init statement allows you to do things before the game starts. Characters, names, images and others have to be defined in the init block. Images also have to be imported in this block. The init block must be placed above the label start block.

This allows us to do this(instead of what I showed you above):

Code:
    y "My name's Yotsuba!"
    y "I'm from a country... to the left!"
    y "My hair is green!"
    y "I have four pigtails!"


As you can see, using characters simplifies coding a lot. You can also give them individual colors:

Code:

init:
$ y = Character("Yotsuba", color="#aaffaa")

It titles her name in Green. Kinda fits Yotsuba, dontcha think?

Now then, let's create a new set of code for the game. Erase the coding you did so far, and type this instead.

Code:
init:
    $ me = Character("Me", color="#aaaaff")
    $ g = Character("Girl", color="#aaffaa")
    $ y = Character("Yotsuba", color="#aaffaa")

label start:
    me "I wish I had some money"
    me "It's so damn hot, and I can't buy anything..."
    me "...Huh?"
    "I saw something stuck to my shoe on a sliver of gum."
    "I picked it away."
    "It was a 50 buck note!"
    "I love you, lady luck..."
    g "Excuse me, but have you seen a fifty around here?"
    y "My name's Yotsuba, by the way. Nice to meet you!"
    return


See what we did there? This way, you can change a name, by referencing a different declared title. Useful to add some level of realism to your game. (No, you dont have the power to psionically scry a girl's name the moment you lay eyes on'em, nice try, though).

If you save this, and play through it, not much will have changed. However, the code is now tidier, and it's easier to write more lines now.

Congrats, you've learned to create a simple visual novel!

In the next episode of Renpyball Z, it's a fiesta! Goku and Kurt Christen Stewart must fight against branching paths! You'll (FINALLY) learn to create different paths that the player can take. You'll also learn how to get graphics in your game. FINALLY!. And guess who's gonna be the big star?

_________________
Image
Yeap.

_________________
Click the icon to see the image in fullscreen mode  
1 pcs.
Click the icon to see the image in fullscreen mode  
4 pcs.


Thu May 02, 2013 1:58 pm
Profile E-mail WWW
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 
 

Similar topics

 
Flash lessons to get your toes wet. Part 5
Forum: Tokyo U
Author: Pantsman
Replies: 5
Coding with Renpy, part 4.
Forum: Tokyo U
Author: Pantsman
Replies: 3
Electro-convulsive therapy, part one
Forum: ./General Spam
Author: 「H A N Z O」
Replies: 3
Hizzle wasn't part of the glorious German people's republic
Forum: ./General Spam
Author: 「H A N Z O」
Replies: 7
Electro-convulsive therapy, part one
Forum: ./General Spam
Author: 「H A N Z O」
Replies: 2
Top


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Mods Database :: Imprint :: Crawler Feeds :: Reset blocks
Designed by STSoftware for PTF.

Portal XL 5.0 ~ Premod 0.3 phpBB SEO