use of call with parameters [Sloved]

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
User avatar
pyPat
Regular
Posts: 30
Joined: Wed Sep 11, 2019 5:34 pm
Github: patlol
Location: France
Contact:

use of call with parameters [Sloved]

#1 Post by pyPat »

Hello, I have many thumbnail display, via screen, to do during a game. So I had the idea to group the necessary commands in a label called by call. After multiple tests i arrived at this code

Code: Select all

define j = Character("Jhon", color="#c8ffc8")

label play_screen(imageName):
    j "[imageName]"
    pause 1
    screen thumbnail:
        add imageName xalign 0.5 yalign -0.1
        modal False
    show screen thumbnail with dissolve
    return

label start:
    j "Hello!"
    call play_screen(imageName="thumbnail 01.png")

    j "first thumbnail "

    hide screen thumbnail with dissolve
    call play_screen(imageName="thumbnail 02.png")
    
    j "End"
    return
I have the following error message:

Code: Select all

...
While running game code:
  File "game/script.rpy", line 51, in script
  File "game/script.rpy", line 41, in execute
  File "game/script.rpy", line 41, in execute
  File "game/script.rpy", line 42, in execute
NameError: name 'imageName' is not defined

-- Full Traceback ------------------------------------------------------------
...
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "game/script.rpy", line 41, in execute
  File "game/script.rpy", line 41, in execute
  File "game/script.rpy", line 42, in execute
  File "<screen language>", line 42, in <module>
NameError: name 'imageName' is not defined

Linux-4.15.0-20-generic-x86_64-with-debian-buster-sid
Ren'Py 7.3.2.320
Test 1.0
Sat Sep 14 15:17:44 2019
line 42 = add imageName xalign 0.5 yalign -0.1
if i use imageName or [imageName] i have exactly the same message
if i use "imageName" it's run but just text appears.
And yet j "[imageName]" displays the name of the image well ...

If i use screen thumbnail(imageName):
it's return

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 51, in script
Exception: Required parameter imageName has no value.

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

Full traceback:
  File "game/script.rpy", line 51, in script
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ast.py", line 706, in execute
    renpy.exports.say(who, what, *args, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/exports.py", line 1336, in say
    who(what, *args, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 1139, in __call__
    self.do_display(who, what, cb_args=self.cb_args, **display_args)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 842, in do_display
    **display_args)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 591, in display_say
    rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ui.py", line 295, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 2699, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 3091, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 430, in visit_all
    callback(self)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 3091, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 440, in per_interact
    self.update()
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ast.py", line 158, in apply_arguments
    return parameters.apply(args, kwargs, ignore_errors)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ast.py", line 122, in apply
    raise Exception("Required parameter %s has no value." % name)
Exception: Required parameter imageName has no value.

Linux-4.15.0-20-generic-x86_64-with-debian-buster-sid
Ren'Py 7.3.2.320
Test 1.0
Sat Sep 14 15:33:09 2019
line 51: j "first thumbnail "

with screen thumbnail([imageName]):

Code: Select all

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


File "game/script.rpy", line 41: expected 'name' not found.
    screen thumbnail([imageName]):
                     ^

Ren'Py Version: Ren'Py 7.3.2.320
Sat Sep 14 15:36:26 2019
Thanks for your help
Last edited by pyPat on Tue Sep 17, 2019 9:05 am, edited 1 time in total.
English is not my native language; please excuse typing errors.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: use of call with parameters

#2 Post by hell_oh_world »

pyPat wrote: Sat Sep 14, 2019 9:25 am Hello, I have many thumbnail display, via screen, to do during a game. So I had the idea to group the necessary commands in a label called by call. After multiple tests i arrived at this code

Code: Select all

define j = Character("Jhon", color="#c8ffc8")

label play_screen(imageName):
    j "[imageName]"
    pause 1
    screen thumbnail:
        add imageName xalign 0.5 yalign -0.1
        modal False
    show screen thumbnail with dissolve
    return

label start:
    j "Hello!"
    call play_screen(imageName="thumbnail 01.png")

    j "first thumbnail "

    hide screen thumbnail with dissolve
    call play_screen(imageName="thumbnail 02.png")
    
    j "End"
    return
I have the following error message:

Code: Select all

...
While running game code:
  File "game/script.rpy", line 51, in script
  File "game/script.rpy", line 41, in execute
  File "game/script.rpy", line 41, in execute
  File "game/script.rpy", line 42, in execute
NameError: name 'imageName' is not defined

-- Full Traceback ------------------------------------------------------------
...
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "game/script.rpy", line 41, in execute
  File "game/script.rpy", line 41, in execute
  File "game/script.rpy", line 42, in execute
  File "<screen language>", line 42, in <module>
NameError: name 'imageName' is not defined

Linux-4.15.0-20-generic-x86_64-with-debian-buster-sid
Ren'Py 7.3.2.320
Test 1.0
Sat Sep 14 15:17:44 2019
line 42 = add imageName xalign 0.5 yalign -0.1
if i use imageName or [imageName] i have exactly the same message
if i use "imageName" it's run but just text appears.
And yet j "[imageName]" displays the name of the image well ...

If i use screen thumbnail(imageName):
it's return

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 51, in script
Exception: Required parameter imageName has no value.

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

Full traceback:
  File "game/script.rpy", line 51, in script
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ast.py", line 706, in execute
    renpy.exports.say(who, what, *args, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/exports.py", line 1336, in say
    who(what, *args, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 1139, in __call__
    self.do_display(who, what, cb_args=self.cb_args, **display_args)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 842, in do_display
    **display_args)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 591, in display_say
    rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ui.py", line 295, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 2699, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 3091, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 430, in visit_all
    callback(self)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 3091, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 440, in per_interact
    self.update()
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ast.py", line 158, in apply_arguments
    return parameters.apply(args, kwargs, ignore_errors)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ast.py", line 122, in apply
    raise Exception("Required parameter %s has no value." % name)
Exception: Required parameter imageName has no value.

Linux-4.15.0-20-generic-x86_64-with-debian-buster-sid
Ren'Py 7.3.2.320
Test 1.0
Sat Sep 14 15:33:09 2019
line 51: j "first thumbnail "

with screen thumbnail([imageName]):

Code: Select all

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


File "game/script.rpy", line 41: expected 'name' not found.
    screen thumbnail([imageName]):
                     ^

Ren'Py Version: Ren'Py 7.3.2.320
Sat Sep 14 15:36:26 2019
Thanks for your help
Maybe try to call the screen without its keyword(s). It's not some sort of kwargs based on how you defined it.

Code: Select all

call play_screen("thumbnail 02.png")

User avatar
pyPat
Regular
Posts: 30
Joined: Wed Sep 11, 2019 5:34 pm
Github: patlol
Location: France
Contact:

Re: use of call with parameters

#3 Post by pyPat »

thanks but no don't work

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 16, in script
    
  File "game/script.rpy", line 6, in execute
    screen thumbnail:
  File "game/script.rpy", line 6, in execute
    screen thumbnail:
  File "game/script.rpy", line 7, in execute
    add imageName xalign 0.5 yalign -0.1
NameError: name 'imageName' is not defined

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

Full traceback:
  File "game/script.rpy", line 16, in script
    
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ast.py", line 706, in execute
    renpy.exports.say(who, what, *args, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/exports.py", line 1336, in say
    who(what, *args, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 1139, in __call__
    self.do_display(who, what, cb_args=self.cb_args, **display_args)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 842, in do_display
    **display_args)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/character.py", line 591, in display_say
    rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/ui.py", line 295, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 2699, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 3091, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 430, in visit_all
    callback(self)
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/core.py", line 3091, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 440, in per_interact
    self.update()
  File "/home/patrick/renpy-7.3.2-sdk/renpy/display/screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "game/script.rpy", line 6, in execute
    screen thumbnail:
  File "game/script.rpy", line 6, in execute
    screen thumbnail:
  File "game/script.rpy", line 7, in execute
    add imageName xalign 0.5 yalign -0.1
  File "<screen language>", line 7, in <module>
NameError: name 'imageName' is not defined

Linux-4.15.0-20-generic-x86_64-with-debian-buster-sid
Ren'Py 7.3.2.320
Test 1.0
Sat Sep 14 17:01:18 2019
English is not my native language; please excuse typing errors.

User avatar
pyPat
Regular
Posts: 30
Joined: Wed Sep 11, 2019 5:34 pm
Github: patlol
Location: France
Contact:

Re: use of call with parameters

#4 Post by pyPat »

Eureka !!! with this code is ok
if i understand correctly ren py does not have variable it is necessary to declare a variable via python and after using it in ren py is that it?
but why in this way j "[imageName]" displays the name of the image well ???

Code: Select all

define j = Character("Jhon", color="#c8ffc8")

label play_screen(imageName):
    j "[imageName]"
    pause 1
    $ nameThumbnail = imageName
    screen thumbnail:
        # add imageName xalign 0.5 yalign -0.1  : don't work
        add nameThumbnail xalign 0.5 yalign -0.1
        modal False
    show screen thumbnail with dissolve
    return

label start:
    j "Hello!"
    call play_screen("thumbnail 01.png")

    j "first thumbnail "

    hide screen thumbnail with dissolve
    call play_screen("thumbnail 02.png")

    j "End"
English is not my native language; please excuse typing errors.

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: use of call with parameters

#5 Post by drKlauz »

Why not simple give screen parameter it use?

Code: Select all

screen thumbnail(imageName):
  ...

label play_screen(imageName):
  ...
  show screen thumbnail(imageName) with dissolve
  ...

label start:
  ...
  call play_screen('thumb_01.png')
  ...
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: use of call with parameters

#6 Post by Kia »

you should pass the variable to the screen to use it in the screen. the variables passed as arguments are local to the labels or screens and can't be used outside of them unless they are passed around.

Code: Select all

define j = Character("Jhon", color="#c8ffc8")

screen thumbnail(imageName):
    add imageName xalign 0.5 yalign .5
    modal False

label play_screen(imageName):
    j "[imageName]"
    pause 1
    show screen thumbnail(imageName) with dissolve
    return

label start:
    j "Hello!"
    call play_screen(imageName="thumbnail 01.png")

    j "first thumbnail "

    hide screen thumbnail with dissolve
    call play_screen(imageName="thumbnail 02.png")
    
    j "End"
    return
@hell_oh_world please read your private messages

User avatar
pyPat
Regular
Posts: 30
Joined: Wed Sep 11, 2019 5:34 pm
Github: patlol
Location: France
Contact:

Re: use of call with parameters

#7 Post by pyPat »

Ok, I understand now
or I declare a python variable will be global
or I pass the local variable of a block to another.

Of course I should have thought. Thank you
English is not my native language; please excuse typing errors.

Post Reply

Who is online

Users browsing this forum: No registered users