Page 1 of 1

Trouble calling a self-made function from screen

Posted: Wed Oct 17, 2018 10:33 pm
by zeroTheHero
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?

Re: Trouble calling a self-made function from screen

Posted: Thu Oct 18, 2018 5:27 am
by Remix
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 )

Re: Trouble calling a self-made function from screen

Posted: Sun Oct 28, 2018 6:16 am
by martingerdes
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:

Re: Trouble calling a self-made function from screen

Posted: Sun Oct 28, 2018 11:31 am
by martingerdes
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.)

Re: Trouble calling a self-made function from screen

Posted: Sun Oct 28, 2018 11:38 am
by trooper6
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?

Re: Trouble calling a self-made function from screen

Posted: Sun Oct 28, 2018 1:57 pm
by Remix
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

Re: Trouble calling a self-made function from screen

Posted: Sun Oct 28, 2018 4:25 pm
by trooper6
Interesting! Thanks Remix!