[SOLVED] Passing Image to a Label Sub-Routine Issue

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
guiltyGG
Newbie
Posts: 13
Joined: Sat Aug 19, 2017 8:51 am
Contact:

[SOLVED] Passing Image to a Label Sub-Routine Issue

#1 Post by guiltyGG »

I'm new to Ren'Py and this feels like it should be simple beyond words, but I cannot for the life of me pass an image to a function; I've googled, searched and prayed for answers, but nope, nothing (which probably means this is a fundamental issue with my understanding of Ren'Py).

The source code (I'm still learning, so this won't be pretty):

Code: Select all

label DisplayCrawl(image_name, tInitialPause=1.0, tCrawlTime=7.0, yStart=1.0, yEnd=0.0):
    # hide UI elements
    window hide
    hide screen hud
    $ quick_menu = False
    
    # display image and transition vertically based on passed arguments over x time
    scene image_name with dissolve:
        subpixel True
        yalign yStart
        pause tInitialPause
        linear tCrawlTime yalign yEnd
    pause

    # show UI elements
    show screen hud
    $ quick_menu = True
    return
Will be called as such:

Code: Select all

call DisplayCrawl("some_image", 1.0, 3.0, 1.0, 0.1) # have tried the image name without quotation marks
And, some_image is defined as (though it can be any declared image):

Code: Select all

image some_image = ("crawls/test.png")
In its current state, it will run but just display a grey screen as though it can't find the image, and continue running the rest of the VN as normal.

I was kind of hoping that even though the argument 'image_name' in the label/function is an object, Ren'Py would search for the name of the object passed, realise it's an image / cast the object into an image, and feed that image to the 'scene' statement. Nope. If don't enclose the image name in quotation marks ("some_image"), Ren'Py throws an exception:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 551, in script call
    call DisplayCrawl(some_image, 1.0, 3.0, 1.0, 0.1)
  File "game/script.rpy", line 333, in script
    label DisplayCrawl(image_name, tInitialPause=1.0, tCrawlTime=7.0, yStart=1.0, yEnd=0.0):
  File "game/script.rpy", line 551, in <module>
    call DisplayCrawl(some_image, 1.0, 3.0, 1.0, 0.1)
NameError: name 'some_image' is not defined

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

Full traceback:
  File "game/script.rpy", line 551, in script call
    call DisplayCrawl(some_image, 1.0, 3.0, 1.0, 0.1)
  File "game/script.rpy", line 333, in script
    label DisplayCrawl(image_name, tInitialPause=1.0, tCrawlTime=7.0, yStart=1.0, yEnd=0.0):
  File "C:\Users\###\Desktop\renpy-6.99.12.4-sdk\renpy\ast.py", line 1327, in execute
    args, kwargs = self.arguments.evaluate()
  File "C:\Users\###\Desktop\renpy-6.99.12.4-sdk\renpy\ast.py", line 184, in evaluate
    args.append(renpy.python.py_eval(v, locals=scope))
  File "C:\Users\###\Desktop\renpy-6.99.12.4-sdk\renpy\python.py", line 1749, in py_eval
    return py_eval_bytecode(code, globals, locals)
  File "C:\Users\###\Desktop\renpy-6.99.12.4-sdk\renpy\python.py", line 1743, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 551, in <module>
    call DisplayCrawl(some_image, 1.0, 3.0, 1.0, 0.1)
NameError: name 'some_image' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 6.99.12.4.2187
It seems many peope who use these 'crawl'-like graphical techniques just copy/paste the code where it's needed, though I would prefer a single function to do this (I'm hoping it's just me being stupid and this is an insanely easy thing to do).

Other than that, loving Ren'Py and all its possibilities :)

Thanks,
Last edited by guiltyGG on Sun Aug 20, 2017 2:11 am, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Passing Image to a Label Sub-Routine Issue

#2 Post by PyTom »

This is probably where "scene expression" comes in handy. It takes a displayable, which can be the name of an image. So I'd change your code to be:

Code: Select all

label DisplayCrawl(image_name, tInitialPause=1.0, tCrawlTime=7.0, yStart=1.0, yEnd=0.0):
    # hide UI elements
    window hide
    hide screen hud
    $ quick_menu = False
    
    # display image and transition vertically based on passed arguments over x time
    scene expression image_name as crawl with dissolve:
        subpixel True
        yalign yStart
        pause tInitialPause
        linear tCrawlTime yalign yEnd
    pause

    # show UI elements
    show screen hud
    $ quick_menu = True
    return
And I think it'll work. (The as crawl clause tags it as crawl, so you can do "hide crawl" later to get rid of it.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

guiltyGG
Newbie
Posts: 13
Joined: Sat Aug 19, 2017 8:51 am
Contact:

Re: Passing Image to a Label Sub-Routine Issue

#3 Post by guiltyGG »

Yep, that worked like a charm!

So, all I do to use the function is:

Code: Select all

call DisplayCrawl("some_image", 1.0, 7.0, 1.0, 0.0)
or, usually:

Code: Select all

call DisplayCrawl("some_image")
and, bam!, reusable image crawler code.

A million thanks!!

Righty, back to getting this game whipped into shape :D

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]