Calls to local labels via expression lack scope

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
AEhere
Newbie
Posts: 1
Joined: Sat Apr 10, 2021 11:35 am
Contact:

Calls to local labels via expression lack scope

#1 Post by AEhere »

I was trying to set up a global label at the beginning of a conversation file, followed by a discriminant to call the right local label within that. But whenever I called the local label through an expression, it would only work if I provided the full label name, not just the local part. Here's an MWE:

Code: Select all

label start:

label global_label_1:

    label .local_1:
        "This is label 1-1"

    label .local_2:
        "This is label 1-2"

label global_label_2:

    call .local_2                             #Case 1
    # call expression "global_label_2.local_2"  #Case 2
    # call expression ".local_2"                #Case 3

    label .local_1:
        "This is label 2-1"

    label .local_2:
        "This is label 2-2"

    return
Three different cases of the same call can be found inside global_label_2: the first two provide the expected result where the script goes through the labels in the order [1-1, 1-2, 2-2, 2-1, 2-2], but when case 3 is used the program throws an exception:
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/script.rpy", line 22, in script call
call expression ".local_2" #Case 3
File "game/script.rpy", line 22, in script call
call expression ".local_2" #Case 3
ScriptError: could not find label '.local_2'.

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

Full traceback:
File "game/script.rpy", line 22, in script call
call expression ".local_2" #Case 3
File "D:\RenPy\renpy-7.3.5-sdk\renpy\ast.py", line 1436, in execute
rv = renpy.game.context().call(label, return_site=self.next.name)
File "game/script.rpy", line 22, in script call
call expression ".local_2" #Case 3
File "D:\RenPy\renpy-7.3.5-sdk\renpy\script.py", line 898, in lookup
raise ScriptError("could not find label '%s'." % str(original))
ScriptError: could not find label '.local_2'.

Windows-8-6.2.9200
Ren'Py 7.3.5.606
locallabeltest 1.0
Sat Apr 10 18:03:32 2021
It seems that using expressions to provide label names precludes the use of the global/local nesting functionality, since you always need to provide the full label name. Is there a way to make use local labels and expressions together? Am I missing something here?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Calls to local labels via expression lack scope

#2 Post by Ocelot »

You are not missing anything. When lexer finds normal jump with local label, it modifies label name, prepending current global label name to it and then sends that name to AST. If it encounters jump expression it just sends that expression to AST without parsing it.

It is working as designed. Unfortunately, it appears that there is no way to get current global label name, as it is known only to lexer and you do not have access to it.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: No registered users