How do I get outcome of function in screen?[solved]

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
Love&Peace
Regular
Posts: 52
Joined: Wed Dec 17, 2014 8:19 pm
Contact:

How do I get outcome of function in screen?[solved]

#1 Post by Love&Peace » Mon Feb 15, 2016 8:58 am

Hi. I have a trouble with using function.

Here is my sample code

Code: Select all

init python:
    result = str()
    def someFunction():
        if user_action == "o":
            result = "correct"
        elif user_action == "x":
            result = "wrong"
        return result

screen someScreen:
    textbutton _("button"):
        action [someFunction(), Show("dashboard")]

screen dashboard:
    text result
But when I click button, Renpy shows me an error message

Code: Select all

TypeError: 'unicode' object is not callable
스크린샷 2016-02-15 오후 9.58.11.png
Please help me.
Last edited by Love&Peace on Mon Feb 15, 2016 11:02 pm, edited 1 time in total.

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: How do I get outcome of function in screen?

#2 Post by mobychan » Mon Feb 15, 2016 10:30 am

Try using renpy.curry:

Code: Select all

init python:
    result = str()
    def someFunction():
        if user_action == "o":
            result = "correct"
        elif user_action == "x":
            result = "wrong"
        return result
    someFunctionCurried = renpy.curry(someFunction)

screen someScreen:
    textbutton _("button"):
        action [someFunctionCurried(), Show("dashboard")]

screen dashboard:
    text result

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

Re: How do I get outcome of function in screen?

#3 Post by trooper6 » Mon Feb 15, 2016 12:28 pm

If you want to use a function inside of a screen or screen element, you can't just put it in there like you are doing, you have to use the Function screen action: http://www.renpy.org/doc/html/screen_ac ... l#Function

That said...there are bunch of things about your function itself that won't work...but, I assume what you've written isn't the real function, right?
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

Love&Peace
Regular
Posts: 52
Joined: Wed Dec 17, 2014 8:19 pm
Contact:

Re: How do I get outcome of function in screen?

#4 Post by Love&Peace » Mon Feb 15, 2016 7:06 pm

trooper6 wrote:If you want to use a function inside of a screen or screen element, you can't just put it in there like you are doing, you have to use the Function screen action: http://www.renpy.org/doc/html/screen_ac ... l#Function

That said...there are bunch of things about your function itself that won't work...but, I assume what you've written isn't the real function, right?
No, it isn't.

Just sample.

I've just removed return line, and my function worked... :shock:

neowired
Regular
Posts: 199
Joined: Mon Dec 01, 2008 2:33 pm
Contact:

Re: How do I get outcome of function in screen?

#5 Post by neowired » Mon Feb 15, 2016 9:02 pm

Code: Select all

init python:
    result = str()
    def someFunction():
        if user_action == "o":
            result = "correct"
        elif user_action == "x":
            result = "wrong"
        return result

screen someScreen:
    textbutton _("button"):
        action [someFunction(), Show("dashboard")]
I think the correct explanation of your error would be:
your action executes function someFunction(), the function returns "correct" or "wrong"
which results in:

Code: Select all

action ["correct", Show("dashboard")]
the things in the bracket are "callables"
"correct" is a string/word, unicode

something like Show() is a valid "callable"
something like a string "correct" is not a valid "callable" for action
hence your code results in

Code: Select all

action ["correct", Show("dashboard")]
and throws an error like
TypeError: 'unicode' object is not callable
which means: the string "correct" is not a valid attribute for "action"

when you remove return from your function, it doesn't return anything, so I think you end up with

Code: Select all

action [Show("dashboard")]
hence, you get no errors

Love&Peace
Regular
Posts: 52
Joined: Wed Dec 17, 2014 8:19 pm
Contact:

Re: How do I get outcome of function in screen?

#6 Post by Love&Peace » Mon Feb 15, 2016 11:01 pm

neowired wrote:

Code: Select all

init python:
    result = str()
    def someFunction():
        if user_action == "o":
            result = "correct"
        elif user_action == "x":
            result = "wrong"
        return result

screen someScreen:
    textbutton _("button"):
        action [someFunction(), Show("dashboard")]
I think the correct explanation of your error would be:
your action executes function someFunction(), the function returns "correct" or "wrong"
which results in:

Code: Select all

action ["correct", Show("dashboard")]
the things in the bracket are "callables"
"correct" is a string/word, unicode

something like Show() is a valid "callable"
something like a string "correct" is not a valid "callable" for action
hence your code results in

Code: Select all

action ["correct", Show("dashboard")]
and throws an error like
TypeError: 'unicode' object is not callable
which means: the string "correct" is not a valid attribute for "action"

when you remove return from your function, it doesn't return anything, so I think you end up with

Code: Select all

action [Show("dashboard")]
hence, you get no errors
I noticed I totally made mistake while dealing with data, variables.

So, I'm now trying to rebuild algorithm first :(

Thanks for your reply!

Post Reply

Who is online

Users browsing this forum: Jackkel Dragon