Trouble calling a self-made function from screen

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
zeroTheHero
Regular
Posts: 36
Joined: Mon May 07, 2018 10:49 am
Contact:

Trouble calling a self-made function from screen

#1 Post by zeroTheHero » Wed Oct 17, 2018 10:33 pm

Hey, I'm having some major headache trying to call a function from screen and would like some help. This is what my code looks like:

Code: Select all

frame:
...
	vbox:
		yalign 0.5
    		textbutton "%s"%(choice1) style "choicez" action NullAction(), SetScreenVariable(Choice1_1, "True")
    		textbutton "%s"%(choice2) style "choicez" action NullAction(), SetScreenVariable(Choice1_2, "True")
showif Choice1_1:
	Function[msg( "Pikachu")]								#First Method I tried; doesn't work	 		

showif Choice 1_2:
	vbox:								#This method doesn't seem to work either :(
		textbutton _("button"):
        		action [msg("Pikachu")]
The error code from the first method:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/Practice.rpy", line 40: u'Function' is not a keyword argument or valid child for the showif statement.
    Function[msg( "Pikachu", "Pika pika Peeeee","charmander20.png", "textbox3.png",  who=True )]
            ^

Ren'Py Version: Ren'Py 7.0.0.196
Thu Oct 18 08:00:59 2018

The error from the second method:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 21, in script
    python:
  File "game/script.rpy", line 26, in <module>
    msg("","",choice1="gagaga", choice2="rely on cuteness and beguile the old fart behind the counter and go aaa a a a a a a a  a")
  File "game/Practice.rpy", line 7, in msg
    renpy.pause()
  File "game/Practice.rpy", line 15, in execute
    screen Part1:
  File "game/Practice.rpy", line 15, in execute
    screen Part1:
  File "game/Practice.rpy", line 16, in execute
    frame background Bak:
  File "game/Practice.rpy", line 17, in execute
    frame background None :
  File "game/Practice.rpy", line 18, in execute
    viewport:
  File "game/Practice.rpy", line 20, in execute
    vbox spacing 15:
  File "game/Practice.rpy", line 22, in execute
    for message in m_msg:
  File "game/Practice.rpy", line 28, in execute
    if image1:
  File "game/Practice.rpy", line 38, in execute
    showif Choice1_1:
  File "game/Practice.rpy", line 39, in execute
    vbox:
  File "game/Practice.rpy", line 40, in execute
    textbutton _("button"):
  File "game/Practice.rpy", line 40, in keywords
    textbutton _("button"):
TypeError: 'unicode' object is not callable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 21, in script
    python:
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\ast.py", line 862, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\python.py", line 1912, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 26, in <module>
    msg("","",choice1="gagaga", choice2="rely on cuteness and beguile the old fart behind the counter and go aaa a a a a a a a  a")
  File "game/Practice.rpy", line 7, in msg
    renpy.pause()
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\exports.py", line 1330, in pause
    rv = renpy.ui.interact(mouse='pause', type='pause', roll_forward=roll_forward)
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\core.py", line 2649, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\core.py", line 3033, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\screen.py", line 424, in visit_all
    callback(self)
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\core.py", line 3033, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\screen.py", line 434, in per_interact
    self.update()
  File "C:\Users\newmiracleeveryday\Desktop\renpy-6.99.14.3-sdk\renpy\display\screen.py", line 619, in update
    self.screen.function(**self.scope)
  File "game/Practice.rpy", line 15, in execute
    screen Part1:
  File "game/Practice.rpy", line 15, in execute
    screen Part1:
  File "game/Practice.rpy", line 16, in execute
    frame background Bak:
  File "game/Practice.rpy", line 17, in execute
    frame background None :
  File "game/Practice.rpy", line 18, in execute
    viewport:
  File "game/Practice.rpy", line 20, in execute
    vbox spacing 15:
  File "game/Practice.rpy", line 22, in execute
    for message in m_msg:
  File "game/Practice.rpy", line 28, in execute
    if image1:
  File "game/Practice.rpy", line 38, in execute
    showif Choice1_1:
  File "game/Practice.rpy", line 39, in execute
    vbox:
  File "game/Practice.rpy", line 40, in execute
    textbutton _("button"):
  File "game/Practice.rpy", line 40, in keywords
    textbutton _("button"):
  File "<screen language>", line 41, in <module>
TypeError: 'unicode' object is not callable

Windows-8-6.2.9200
Ren'Py 7.0.0.196
Practice 1.0
Thu Oct 18 07:57:25 2018
Is there something I'm missing or doing wrong?

User avatar
Remix
Miko-Class Veteran
Posts: 993
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Trouble calling a self-made function from screen

#2 Post by Remix » Thu Oct 18, 2018 5:27 am

All the supported screen actions are listed Here
* there are a couple of new ones for local vars in 'used' screens... the rest are documented though.

You will see Function uses parenthesis, not square brace and the arguments and keywords are passed into Function rather than the referenced user function, so:

Function( my_function, arg1, arg2, kwarg1=True, kwarg2=False )
Mad Scientist Todo List:
  • Finish Improved Event Handler
  • Implement DragonBones animation as a Creator Defined Container
  • Finish Catmull-Rom Spline pathing
  • Finish Bitmask collision and rebound vector system
  • Develop time based building mechanic
  • Others
  • *Find a superb artist and actually write a game*

martingerdes
Newbie
Posts: 16
Joined: Sun Oct 07, 2018 5:14 am
Contact:

Re: Trouble calling a self-made function from screen

#3 Post by martingerdes » Sun Oct 28, 2018 6:16 am

I'll ressurect this, since it's not that long ago, and I am having precisely the same problem.
I am simply trying to make myself a convenience function to construct strings for me while building up a screen.
And I am failing at this spectacularly... :cry:

Complete testcode:

Code: Select all

python:
  def get_text(): return "its a test string"

screen test_screen():
  frame:
    vbox:
      $ t=Function(get_text)
      text t

label start:

    call screen test_screen
Alternatively I tried the more direct "$t=get_text()"

In both cases I am getting the same error: "NameError: name 'get_text' is not defined" (on the variable assignment to t)

And at least the version "Function(get_text)" surely should work, right?

The fun thing is that I am only stumbling over this now. I am already passing class instance objects to my screens. And those have property methods which execute code to return things. That gets called in screens and it all works great. So I am sure I am overlooking something embarrassingly simple here (maybe a scope problem?). But this thread was the best my googlefu turned up... :roll:

martingerdes
Newbie
Posts: 16
Joined: Sun Oct 07, 2018 5:14 am
Contact:

Re: Trouble calling a self-made function from screen

#4 Post by martingerdes » Sun Oct 28, 2018 11:31 am

Alright, as I expected, it was something utterly dumb:

I wrote "python:" instead of "init python:" :oops:

Code: Select all

init python:
  def get_text(): return "its a test string"

screen test_screen():
  frame:
    vbox:
      $ t=get_text()
      text t

label start:

    call screen test_screen
This works as expected. :)
(I just absolutely could not spot it before, and did not find any simple example code. Maybe this eventually helps somebody else.)
Last edited by martingerdes on Sun Oct 28, 2018 12:59 pm, edited 1 time in total.

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

Re: Trouble calling a self-made function from screen

#5 Post by trooper6 » Sun Oct 28, 2018 11:38 am

Remix wrote:
Thu Oct 18, 2018 5:27 am
All the supported screen actions are listed Here
* there are a couple of new ones for local vars in 'used' screens... the rest are documented though.
Hi Remix! I think I might have missed the new functions in used screens—could you say more on what they are, or link to the threads that talk about them?
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

User avatar
Remix
Miko-Class Veteran
Posts: 993
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Trouble calling a self-made function from screen

#6 Post by Remix » Sun Oct 28, 2018 1:57 pm

trooper6 wrote:
Sun Oct 28, 2018 11:38 am
Hi Remix! I think I might have missed the new functions in used screens—could you say more on what they are, or link to the threads that talk about them?
I just keep an eye on the renpy-git channel on discord which summarizes commits, so noticed a couple of new actions were added recently.

12 days ago there was a commit by Tom which points at:

https://github.com/renpy/renpy/commit/4 ... c8b6f89ad2

SetLocalVariable and ToggleLocalVariable added to the Nightlies
Mad Scientist Todo List:
  • Finish Improved Event Handler
  • Implement DragonBones animation as a Creator Defined Container
  • Finish Catmull-Rom Spline pathing
  • Finish Bitmask collision and rebound vector system
  • Develop time based building mechanic
  • Others
  • *Find a superb artist and actually write a game*

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

Re: Trouble calling a self-made function from screen

#7 Post by trooper6 » Sun Oct 28, 2018 4:25 pm

Interesting! Thanks Remix!
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

Post Reply

Who is online

Users browsing this forum: No registered users