How to access button action Function()'s return value?

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
zmc
Newbie
Posts: 5
Joined: Thu Aug 11, 2016 12:23 pm
Contact:

How to access button action Function()'s return value?

#1 Post by zmc »

Say I have a method I use via action Function() in a screen. I want to use the return value that the method returns. How do I get the return value (list of strings) so that I can display them, either in the screen or with a say?

button:
text "Test" size 40
action Function(myObject.method)

I started learning renpy yesterday, so if there are better ways of interacting with buttons and python, please do tell me. I know you can do something like 'action [Function(myObject.method), some other action, some other action], but I haven't fully grasped it.

Thanks!

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: How to access button action Function()'s return value?

#2 Post by nyaatrap »

I also wanted to do it, but couldn't find any way. So I'm using global variables instead of return value. If you change global variables by the Function statement, then it'll update screens immediately.

zmc
Newbie
Posts: 5
Joined: Thu Aug 11, 2016 12:23 pm
Contact:

Re: How to access button action Function()'s return value?

#3 Post by zmc »

I see. I'm trying out just using menus for what I want to do, although I still do want to find out how to do this. I'll try out globals too! Thanks!

User avatar
Pando
Regular
Posts: 29
Joined: Wed Oct 08, 2014 7:57 am
Projects: Crossfire
Organization: Agape Studios
IRC Nick: Pando
Github: Scylardor
Contact:

Re: How to access button action Function()'s return value?

#4 Post by Pando »

FYI, also wanted to do that once. Also ended up using globals. :)
Image

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: How to access button action Function()'s return value?

#5 Post by nyaatrap »

This seems working, though I think using globals is efficient.

Code: Select all

screen test():
    default t="default"
    textbutton t action SetScreenVariable("t", test())
    
init python:
    def test():
        return "changed"

zmc
Newbie
Posts: 5
Joined: Thu Aug 11, 2016 12:23 pm
Contact:

Re: How to access button action Function()'s return value?

#6 Post by zmc »

Oh, that's interesting. I'm gonna try that, but you're right about globals. I felt dirty using them at first, but I'm liking them more and more. Thanks!

Post Reply

Who is online

Users browsing this forum: Andredron, mold.FF