Make a function

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
RyuMaster
Newbie
Posts: 10
Joined: Mon Apr 08, 2013 6:53 am
Contact:

Make a function

#1 Post by RyuMaster » Tue Apr 09, 2013 7:56 am

Hi! Is it possible to make functions from this block of code: (because I'm going to reuse it heavily)
show rose surprised_talk
rosec "Some text.{nw}"
hide rose surprised_talk
show rose surprised
rosec "Some text.{fast}"
So thay I could call it from anywhere like:

function (rose surprised, rose surprised_talk, "Some_Text")

I've tried this and that, but always end up with the errors

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Make a function

#2 Post by Alex » Tue Apr 09, 2013 11:21 am

You could try to put this code in a separate label and call it later from different points of your script
http://www.renpy.org/wiki/renpy/doc/ref ... _Statement

RyuMaster
Newbie
Posts: 10
Joined: Mon Apr 08, 2013 6:53 am
Contact:

Re: Make a function

#3 Post by RyuMaster » Wed Apr 10, 2013 4:58 am

Ah, I wasn't very clear. I want to pass custom parameter there, like

function (_image1, _image1_talk, _text)

so I wondered how to make such function to work, and will it understand all those "hide" and "show" statements inside it.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Make a function

#4 Post by Alex » Wed Apr 10, 2013 4:15 pm

Something like this?

Code: Select all

# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")

image a = "a.png"
image b = "b.png"
image c = "c.png"
       
        
label my_label:
    show expression img_1
    char1 "[text_1]"
    show expression img_2
    "..."
    hide img_1
    hide img_2
    return
    
        
# The game starts here.
label start:

    "Line 1"
    
    $ img_1 = "a"
    $ char1 = e
    $ text_1 = "text 1"
    $ img_2 = "b"
    call my_label from call_1
    
    "Line 2"
    "Line 3"
    
    $ img_1 = "c"
    $ char1 = ""
    $ text_1 = "text 2"
    $ img_2 = "b"
    call my_label from call_2

    e "You've created a new Ren'Py game."

    e "Once you add a story, pictures, and music, you can release it to the world!"

    return

RangerDanger
Regular
Posts: 45
Joined: Wed Jun 27, 2012 11:36 pm
Contact:

Re: Make a function

#5 Post by RangerDanger » Wed Apr 10, 2013 5:38 pm

I believe that you will find the information on this page very helpful.

http://www.renpy.org/doc/html/statement ... lents.html

Post Reply

Who is online

Users browsing this forum: No registered users