[SOLVED] What does "call ... from ..." do?

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
felsenstern
Regular
Posts: 62
Joined: Tue Jul 11, 2017 2:13 am
Contact:

[SOLVED] What does "call ... from ..." do?

#1 Post by felsenstern » Fri Jan 01, 2021 7:16 am

Hiya,

can someone explain me what the following line does?

call visitor from _call_visitor

(This comes from code that was generated by a rpg-maker to renpy converter. I found the label inside a file named custom_menus.rpy. But what I don't understand is everything that starts with the "... from ..." part and why the generator created that part, since it doesn't look like RenPy needs it because when I remove it, the game works just as fine.)
Last edited by felsenstern on Sun Jan 03, 2021 4:53 pm, edited 1 time in total.
---
Yes, I've Read The F*cking Manual
Yes, I've used the f*cking search function
Yes, I've used a site search
No, I don't need a reminder that search functions exist
No, I don't need your astonished outbreak that I couldn't find the information
No, I don't need your answer if you can't just give it without all the BS around it

emanuel
Newbie
Posts: 12
Joined: Fri Dec 25, 2020 8:44 am
Contact:

Re: What does "call ... from ..." do?

#2 Post by emanuel » Fri Jan 01, 2021 7:35 am

It sets a label that is used as a return point for loading saved games. This is used to retain compatibility with saved games from a different version of the same script.

felsenstern
Regular
Posts: 62
Joined: Tue Jul 11, 2017 2:13 am
Contact:

Re: What does "call ... from ..." do?

#3 Post by felsenstern » Sun Jan 03, 2021 3:27 am

Now I am completely confused. My labels change when I make different versions of the same script? Is RenPy doing this? Let's say when I have a label like:

label wolf_event:

how would the call look like to stay compatible no matter what version of the script I use?
---
Yes, I've Read The F*cking Manual
Yes, I've used the f*cking search function
Yes, I've used a site search
No, I don't need a reminder that search functions exist
No, I don't need your astonished outbreak that I couldn't find the information
No, I don't need your answer if you can't just give it without all the BS around it

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: What does "call ... from ..." do?

#4 Post by Imperf3kt » Sun Jan 03, 2021 3:39 am

Your label names shouldnt change, but renpy regularly adds "from <label>" to your calls when compiling rpyc files. It is intended behaviour and call label is just shorthand for the same thing.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

emanuel
Newbie
Posts: 12
Joined: Fri Dec 25, 2020 8:44 am
Contact:

Re: What does "call ... from ..." do?

#5 Post by emanuel » Sun Jan 03, 2021 6:38 am

felsenstern wrote:
Sun Jan 03, 2021 3:27 am
Now I am completely confused. My labels change when I make different versions of the same script? Is RenPy doing this? Let's say when I have a label like:

label wolf_event:

how would the call look like to stay compatible no matter what version of the script I use?
Whenever you call (not jump to) a label, the the return address is pushed on the stack. When a return statement is encountered, it then pops the address off the stack to know where to go to. This works the same as a function in any programming language really.

But a problem arises, when saving between a call and a return. In a later version, the return address might be different (you can think of it as simply the line number where the call is made). So, if you then have multiple calls to the same function, renpy doesn't know where to return to. The from clause simply adds a label, so Renpy always knows where to return. So, in this case:

Code: Select all

main_function:
    call some_function_where_the_user_might_save()
    "Looks like you're still playing..."
    call some_function_where_the_user_might_save()
when loading a saved game, Renpy wouldn't know which call to return to - especially if you change the code. That's why you can add a unique label to each call, like this

Code: Select all

main_function:
    call some_function_where_the_user_might_save() from pointA
    "Looks like you're still playing..."
    call some_function_where_the_user_might_save() from pointB

felsenstern
Regular
Posts: 62
Joined: Tue Jul 11, 2017 2:13 am
Contact:

Re: What does "call ... from ..." do?

#6 Post by felsenstern » Sun Jan 03, 2021 4:04 pm

Thanks a lot Imperf3kt and emanuel for the answers so far. Let me put all your answers together and let me know if I am wrong please!

...from <name>
1. serves as a label for the call when it reaches return.
2. this is done internally, using a stack
3. it can be given by the coder.
4. if not pre-defined, RenPy generates this label when it compiles the program.

so all in all, it's a nice to have when it's given but not necessary at all.
---
Yes, I've Read The F*cking Manual
Yes, I've used the f*cking search function
Yes, I've used a site search
No, I don't need a reminder that search functions exist
No, I don't need your astonished outbreak that I couldn't find the information
No, I don't need your answer if you can't just give it without all the BS around it

emanuel
Newbie
Posts: 12
Joined: Fri Dec 25, 2020 8:44 am
Contact:

Re: What does "call ... from ..." do?

#7 Post by emanuel » Sun Jan 03, 2021 4:46 pm

felsenstern wrote:
Sun Jan 03, 2021 4:04 pm
Thanks a lot Imperf3kt and emanuel for the answers so far. Let me put all your answers together and let me know if I am wrong please!

...from <name>
1. serves as a label for the call when it reaches return.
2. this is done internally, using a stack
3. it can be given by the coder.
4. if not pre-defined, RenPy generates this label when it compiles the program.

so all in all, it's a nice to have when it's given but not necessary at all.
Renpy will generate labels, but there is no guarantee that the labels will get the same generated names in future versions of the same script. In fact, Renpy simply numbers the labels. Thus, if you add a call in a later version, the generated labels will be different. You need to define them manually to be sure that the game returns to the point where you intend it to return to. If you want players of older versions to be able to load their savegames in newer versions that is. Otherwise, you can forget about it.

felsenstern
Regular
Posts: 62
Joined: Tue Jul 11, 2017 2:13 am
Contact:

Re: What does "call ... from ..." do?

#8 Post by felsenstern » Sun Jan 03, 2021 4:52 pm

Thanks a lot!
---
Yes, I've Read The F*cking Manual
Yes, I've used the f*cking search function
Yes, I've used a site search
No, I don't need a reminder that search functions exist
No, I don't need your astonished outbreak that I couldn't find the information
No, I don't need your answer if you can't just give it without all the BS around it

Post Reply

Who is online

Users browsing this forum: Bing [Bot]