Precision on Call Function and how to use them (...properly)

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
User avatar
mugenjohncel
Hentai Poofter
Posts: 2121
Joined: Sat Feb 04, 2006 11:13 pm
Organization: Studio Mugenjohncel
Location: Philippines
Contact:

Precision on Call Function and how to use them (...properly)

#1 Post by mugenjohncel »

OK... here I am once again stuck and found myself looking face to face with the (now familiar to me) traceback error screen.

My code is now officially a jungle and is now very, very hard to look at (not to mention very hard to understand and I now scroll up and down quite often... very, very long scrolls).

Until I tried to look at the demo and saw a line like this...

Code: Select all

e "Hi, and welcome to the Ren'Py demo game."

    show eileen happy
    
    e "My name is Eileen, and I'm here to demonstrate some of the features of the Ren'Py visual novel engine."

    # Show the editor button, which is defined in editor.rpy.
    $ show_editor_button = True

    e "See that button in the upper-right corner of the screen?"

    e "It shows where we are in the script. You can click it, and we'll try to open the file in a text editor."

    e "It's an easy way to see how you can use the features I'm showing off."

    e "We'll only show it for code that's intended to be easy to understand."

    call demos from _call_demos_1
Call Function?... I said to myself... and decided to look at the game directory and found several more files like...
demo_animation.rpy
demo_transitions.rpy
and the list goes on...
And carefully examined each one and noticed they all have one thing in common...

at the bottom of the code is a very, very familiar line that says...
return
OK... This is how I understand it (Correct me if I'm wrong)

Ren'py will run as usual and when it reaches a section that looks like this...

Code: Select all

e "We'll only show it for code that's intended to be easy to understand."

    call demos from _call_demos_1
It will list the other files and from there you will choose one of them and In my case I choose "Animations" and I will now jump to a file called "demo_animation.rpy" and at the bottom of the file when I reach a section that says...

Code: Select all

return
I will be magically teleported back to "script.rpy"...

(Again... correct me if I'm wrong)

Now here's my question :?:

In my code I will have a thing like this...
Mr. K
Let's see...

Mr. K
First, Mika invited me to eat lunch with her in the gym...

Mr. K
Second, Elena said she'll bring me lunch.

Mr. K
But I've heard rumors that the library is now being flocked by students.

Mr. K
Male students to be more precise.
Then a label (Choice) will pop up and you will choose from...
Choice 1
Leave faculty room and go see Mika

Choice 2
Wait for Elena

Choice 3
Feed curiosity and go to library
What I wanted to happen is if you choose...
Choice 1
You will be magically teleported to a file named mika.rpy

Choice 2
You will be magically teleported to a file named elena.rpy

Choice 3
You will be magically teleported to a file named lucy.rpy
But, what I wanted is a bit more precision...

Let's say that I am now inside the file mika.rpy

and inside is a line that looked like this...
Mika
Uh... aren't you supposed to be going back to your class now.

Mr. K
Nah... let me lie here for 5 more minutes.

Mika
I'm dissapointed in you... I can't believe those words are coming from a teacher.

Mr. K
OK... I'll go now.
What I wanted here is for us to be teleported back to the original script (script.rpy) but this time I wanted to be teleported precisely to a label named "class_b_1" inside the original script (script.rpy).

In short...

What I'm asking here is if possible, could someone tell me how to jump from one file to another like for example I am inside a file named script.rpy and wanted to jump to a very precise label inside mika.rpy (example - label eatlunch_a)

The reason why I wanted to do this is I wanted to divide my code into tiny easily readable, managable bits.

Thanks in advance.

(goes back to work...)

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#2 Post by PyTom »

Hm... you seem to have misunderstood a little. The call statement always calls a label, never a filename. In each of the files you give, there is a label with the same name as the file... that's where control is going to.

The actual filenames do not matter, it's only the label names that matter.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
mugenjohncel
Hentai Poofter
Posts: 2121
Joined: Sat Feb 04, 2006 11:13 pm
Organization: Studio Mugenjohncel
Location: Philippines
Contact:

#3 Post by mugenjohncel »

Uh... So does this mean I can Jump from a label on another file...
Example

This label is inside "script.rpy"

Code: Select all

label cafeteria:
    Mr. K "Man!... your food SUCKS BIGTIME!"
    Mr. K "Don't you have anything edible here"
    Cman "Whoa!... Don't look at me"
    Cman "I'm just doing my job... OK"
    Mr. K "That's it!... Who's responsible for this"
    Cman "Her"
    ## This is the big questionmark here?...
    ## I need working example for this one
    ## Now I wanted to jump to another label but...
    ## This time I wanted to jump to a label located
    ## On a different file.
Then the script will jump to a label found on another file...

This label is inside "oldbitch.rpy"

Code: Select all

label oldbitch:
    "Are you the one responsible here?..."
    ## To be continued...


If this behavior is possible please teach me... and sorry about my horrible english...

Thanks in advance.

derik
Regular
Posts: 57
Joined: Wed Oct 18, 2006 4:56 am
Contact:

#4 Post by derik »

mugenjohncel wrote:Uh... So does this mean I can Jump from a label on another file...
The various .rpy files are for your convienience as a writer- so you dont' have to scroll through 10 pages of image declarations in one enormous script.rpy file.

The first time you launch the renpy project after having made a change to any of the .rpy files, the program takes all the .rpy files and pastes them together end-to-end into a file called, IIRC, script.rpyc. (the c stands for compiled, or possibly collated) That's what it runs. So from renpy's perspective-- there's just one file. The separate files are just an illusion for your convenience.

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#5 Post by monele »

In your cafetaria/oldbitch example, just use

Code: Select all

jump oldbitch
Ren'Py doesn't care in which files the labels are. Just use the label name and it'll go there, whatever the file it's in ^^.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#6 Post by PyTom »

Derik is basically right on this one. We actually do, for speed purposes, have multiple .rpyc files, but logically they are all treated as one big file. You can jump and call between files in the exact same way as you jump and call within a file.

The flip side of this is that a label can only appear in one file. (For example, you can only have one start label in the program... but it doesn't matter which file it appears in.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

dizzcity
Veteran
Posts: 311
Joined: Thu Aug 17, 2006 10:51 am
Projects: Lakeside Sunset, Wedding Vows, Working Woman
Location: Singapore
Contact:

#7 Post by dizzcity »

That's actually tremendously helpful to know. I've always wanted to find out too, so I'm glad about this answer. Already it suggests new ways of writing stories, especially anthologies or round-robin projects, and even class-based interactive fiction. Must explore more in one of my future projects.

-Dizzy-
A smart man follows the rules, a dumb man breaks them. A great man bends the rules and thus creates them.
Fanfiction.net Profile.
Writer and director of Working Woman (NaNoRenO March 2010)
Writer and director of Wedding Vows (finished 2009).
Creator of Lakeside Sunset (finished 2006).

Post Reply

Who is online

Users browsing this forum: No registered users