Problems with Call Statement

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
Giovedi
Regular
Posts: 147
Joined: Sun Sep 09, 2012 6:20 am
Contact:

Problems with Call Statement

#1 Post by Giovedi »

Disclaimer: I'm posting this on behalf of my nanoreno partner, who doesn't have a forum account. The problem is as follows, copypasta'd from a chat window and illustrated with a diagram that even I have trouble comprehending...

What we're tryna do:
What I want.png
What seems to be happening:
What's happening.png
so I labeled them kinda like... after event one, I use a call function to go to base choices, and then it returns to continue to event 2
and when I use the call function again after event 2 to go to base choices
it ends up returning to before event 2, playing event 2 again
and then calling over to the base choices
and making an infinite loop
Any help? I'm useless and my partner is stumped. It'd be much appreciated.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Problems with Call Statement

#2 Post by xavimat »

We need to see the code to understand where the problem is. Your description of how the call and return should work is correct.
There could be a nested call without return that breaks the expected flow, or something like that.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

izuma
Newbie
Posts: 6
Joined: Fri Mar 06, 2015 12:00 pm
Contact:

Re: Problems with Call Statement

#3 Post by izuma »

Hello, I'm working with Giovedi on this nanoreno and I got an account just so I can elaborate on this quickly. For now most of the text is filled with filler dialogue so I can figure this code easier:

Code: Select all

scene bg bedroom
with fade
"It's day two, time to go to school but wait I can do a thing first, what do I do?"
call basechoice01

Code: Select all

label basechoice01:
menu:
    "Go and study":
        call study01
    "Talk to someone":
        menu:
            "Talk to Janet" if janet == False:
                $ janet = True
                call janet02
            "Talk to Emily":
                call emily02
            "Talk to Vincent" if vincent == False:
                $ vincent = True
                call vincent02
Then I have the individual character routes on a separate script page:

Code: Select all

label emily02:
scene bg library
with fade
e "Do you need something?"
menu:
    "Find study material":
        p "I want to find something"
        e "Oh ok"
        call bookrec
    "Make small talk" if emily == False:
        $ emily = True
        $ epoints +=1
        "Dialogue"
        return
Book rec has its own thing with a bunch of numbers:

Code: Select all

label bookrec: 
e "Oh well I have these books here but right now you can only study one subject with these, which would you like?"
    menu: 
        "Science":
            "wow I know so much science."
            $ scipoints +=8
            return
        "Lit":
            "Literature is literally great."
            $ litpoints +=8
            return
        "Math":
            "MATHEMATICAL."
            $ mathpoints +=8
            return

Code: Select all

label janet02:
    $ jpoints +=1
    j "Oh hello, [povname], do you need anything?"
    p "Just wanted to talk!"
    "and stuff here"
    return

Code: Select all

label vincent02:
    $ vpoints +=1
    scene bg livingroom
    with fade
    v "Oh it's you"
    p "Yeah it's me."
    return
And then I go to the second event...

Code: Select all

scene bg foyer
with fade
j "Ah! Get to school, [povname]!"
scene bg school
with fade
"some stuff happens here."
scene bg front
with fade
"home at last"
scene bg foyer
with fade
j "Welcome home, now that you're home, you can do a couple of things."
"What do I want to do?"
call basechoice01
And it goes to basechoice01 but returns to the beginning of event 2 and just returns and stuff. i'm try to make it so that the player can only pick one person throughout the entire day but have 3 opportunities to do things. (Event 3 not shown since it's not important to the problem.) I hope this can explain my problem better.

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Problems with Call Statement

#4 Post by philat »

How are you going to the second event?
Last edited by philat on Fri Mar 06, 2015 1:21 pm, edited 2 times in total.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Problems with Call Statement

#5 Post by xavimat »

- First. Check your indentation. Ren'Py still works with some odd indents, but it's better to avoid that. After every colon (:) you should always indent.

- Second. Check that all your labels finish with return or jump:
--- Your label "basechoice01" has a menu with three options. All three "call" some label. This means that when the called labels reach a "return" the game flow will return to the next line of that "call". BUT this menu has nothing after the calls. What does Ren'Py do?: goes on to the next line of the file.
--- label emily02: there are two options in the menu. One "returns" to label "basechoice01", to the next line (the non existent line). The other one presents a "call bookrec". This means: when "bookrec" returns, it will return to the next line in "emily02". But there is nothing there. Again, Ren'Py goes on in the file.
--- label bookrec: this one has a menu with three options and all of them have a "return". This is Ok. There are no loose ends here.

In short: control the flow of your code. Every label must finish with a jump or return, not with a call.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

izuma
Newbie
Posts: 6
Joined: Fri Mar 06, 2015 12:00 pm
Contact:

Re: Problems with Call Statement

#6 Post by izuma »

xavimat wrote:- First. Check your indentation. Ren'Py still works with some odd indents, but it's better to avoid that. After every colon (:) you should always indent.

- Second. Check that all your labels finish with return or jump:
--- Your label "basechoice01" has a menu with three options. All three "call" some label. This means that when the called labels reach a "return" the game flow will return to the next line of that "call". BUT this menu has nothing after the calls. What does Ren'Py do?: goes on to the next line of the file.
--- label emily02: there are two options in the menu. One "returns" to label "basechoice01", to the next line (the non existent line). The other one presents a "call bookrec". This means: when "bookrec" returns, it will return to the next line in "emily02". But there is nothing there. Again, Ren'Py goes on in the file.
--- label bookrec: this one has a menu with three options and all of them have a "return". This is Ok. There are no loose ends here.

In short: control the flow of your code. Every label must finish with a jump or return, not with a call.
Thank you for your prompt reply! What I understood from what you said about "basechoice01" I need to have a "return" at the end of it like so?

Code: Select all

label basechoice01:
menu:
    "Go and study":
        call study01
    "Talk to someone":
        menu:
            "Talk to Janet" if janet == False:
                $ janet = True
                call janet02
            "Talk to Emily":
                call emily02
            "Talk to Vincent" if vincent == False:
                $ vincent = True
                call vincent02
    return
And about Emily02, since bookrecs goes to its own label and then returns to Emily02, should I then end the bookrecs link with a return like so?

Code: Select all

label emily02:
scene bg library
with fade
e "Do you need something?"
menu:
    "Find study material":
        p "I want to find something"
        e "Oh ok"
        call bookrec
        return
    "Make small talk" if emily == False:
        $ emily = True
        $ epoints +=1
        "Dialogue"
        return

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Problems with Call Statement

#7 Post by xavimat »

"Emily02": Yes. You can have a return in every choice or a final return at the end of the label. This example works the same. Chose what you think is more readable:

Code: Select all

label emily02:
    scene bg library
    with fade
    e "Do you need something?"
    menu:
        "Find study material":
            p "I want to find something"
            e "Oh ok"
            call bookrec
        "Make small talk" if emily == False:
            $ emily = True
            $ epoints +=1
            "Dialogue"
    return
Also, remember to indent properly (after "label" too). Your code works the same but seems less clear.

"basechoice01": Maybe, I don't know. You haven't showed what line follows the "call basechoice01", in your first piece of code. Your return at the end of basechoice01 will reach that point. OR you can use "jump" instead, to the label "basechoice02" if you have one.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

izuma
Newbie
Posts: 6
Joined: Fri Mar 06, 2015 12:00 pm
Contact:

Re: Problems with Call Statement

#8 Post by izuma »

"basechoice01": Maybe, I don't know. You haven't showed what line follows the "call basechoice01", in your first piece of code. Your return at the end of basechoice01 will reach that point. OR you can use "jump" instead, to the label "basechoice02" if you have one.
Ah I wasn't clear I guess.
Following right after basechoice01 is the second event so it goes like this:

Code: Select all

scene bg bedroom
with fade
"It's day two, time to go to school but wait I can do a thing first, what do I do?"
call basechoice01

label basechoice01:
    menu:
        "Go and study":
            call study01
        "Talk to someone":
            menu:
                "Talk to Janet" if janet == False:
                    $ janet = True
                    call janet02
                "Talk to Emily":
                    call emily02
                "Talk to Vincent" if vincent == False:
                    $ vincent = True
                    call vincent02

scene bg foyer
with fade
j "Ah! Get to school, [povname]!"
scene bg school
with fade
"some stuff happens here."
scene bg front
with fade
"home at last"
scene bg foyer
with fade
j "Welcome home, now that you're home, you can do a couple of things."
"What do I want to do?"
call basechoice01

"I can do one more thing, what else do I want to do?"
call basechoice01
I tried putting the return at the end of label basechoice01 to make

Code: Select all

label basechoice01:
    menu:
        "Go and study":
            call study01
        "Talk to someone":
            menu:
                "Talk to Janet" if janet == False:
                    $ janet = True
                    call janet02
                "Talk to Emily":
                    call emily02
                "Talk to Vincent" if vincent == False:
                    $ vincent = True
                    call vincent02
    return
But it ends up skipping most of my events and going through some weird path I don't want.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Problems with Call Statement

#9 Post by trooper6 »

Your flow is messed up.

Here is my recommendation. Create a band new renpy file that you call: calls.rpy

In that file, put whatever labels you will be calling to...make sure there is a return at the end of each of those labels to bring you back to where you called from.
(if you jump to a label, you can jump back somewhere else...if you call a label, you have to return back to where you came).

So your main script file would look like this:

Code: Select all

scene bg bedroom
with fade
"It's day two, time to go to school but wait I can do a thing first, what do I do?"
call basechoice01 #The game will jump over to the basechoice01 label in a different file and when it is finished continue on from here.

scene bg foyer
with fade
j "Ah! Get to school, [povname]!"
scene bg school
with fade
"some stuff happens here."
scene bg front
with fade
"home at last"
scene bg foyer
with fade
j "Welcome home, now that you're home, you can do a couple of things."
"What do I want to do?"
call basechoice01 #The game will jump over to the basechoice01 label in a different file and when it is finished continue on from here.

"I can do one more thing, what else do I want to do?"
call basechoice01 #The game will jump over to the basechoice01 label in a different file and when it is finished continue on from here.
Then you have your calls.rpy file which looks something like:

Code: Select all

label basechoice01:
    menu:
        "Go and study":
            call study01
        "Talk to someone":
            menu:
                "Talk to Janet" if janet == False:
                    $ janet = True
                    call janet02
                "Talk to Emily":
                    call emily02
                "Talk to Vincent" if vincent == False:
                    $ vincent = True
                    call vincent02
    return

label emily02:
    scene bg library
    with fade
    e "Do you need something?"
    menu:
        "Find study material":
            p "I want to find something"
            e "Oh ok"
            call bookrec
        "Make small talk" if emily == False:
            $ emily = True
            $ epoints +=1
            "Dialogue"
    return

label bookrec: 
    e "Oh well I have these books here but right now you can only study one subject with these, which would you like?"
        menu: 
            "Science":
                "wow I know so much science."
                $ scipoints +=8
            "Lit":
                "Literature is literally great."
                $ litpoints +=8
            "Math":
                "MATHEMATICAL."
                $ mathpoints +=8
    return

label janet02:
    $ jpoints +=1
    j "Oh hello, [povname], do you need anything?"
    p "Just wanted to talk!"
    "and stuff here"
    return

label vincent02:
    $ vpoints +=1
    scene bg livingroom
    with fade
    v "Oh it's you"
    p "Yeah it's me."
    return
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

izuma
Newbie
Posts: 6
Joined: Fri Mar 06, 2015 12:00 pm
Contact:

Re: Problems with Call Statement

#10 Post by izuma »

Oh thank you very much! Everything's working now!

Post Reply

Who is online

Users browsing this forum: Alex, Bing [Bot], Google [Bot], LegsWild