Layered Image Not Accepting Class Variables... (solved)

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
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Layered Image Not Accepting Class Variables... (solved)

#1 Post by noeinan »

I am using layered images to have a customizable character + clothing. However, when I try to use variables inside my player class, I keep getting an error saying player is not defined. But I clearly did define player right after the start_label...

Code: Select all

#PLAYER VARIABLES

        $ player = PlayerList()

Code: Select all

layeredimage protag_grapple:

    #Protagonist Nude Base
    #Arm position

    if player.grapple_arms == "tied":
        "protag-grapple_arms_tied"
    elif player.grapple_arms == "up":
        "protag-grapple_arms_up"
    else:
        pass #this should never happen, let's add an error message later

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/code/base-grapple/grapple-overlay.rpy", line 1, in script
    init python:
  File "game/code/base-grapple/grapple-overlay.rpy", line 3, in <module>
    player.grapple_face = "shock"
NameError: name 'player' is not defined

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

Full traceback:
  File "game/code/base-grapple/grapple-overlay.rpy", line 1, in script
    init python:
  File "E:\_RenPy\renpy-7.3.5-sdk\renpy\ast.py", line 914, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "E:\_RenPy\renpy-7.3.5-sdk\renpy\python.py", line 2028, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/code/base-grapple/grapple-overlay.rpy", line 3, in <module>
    player.grapple_face = "shock"
NameError: name 'player' is not defined

Windows-8-6.2.9200
Ren'Py 7.3.5.606
 
Fri Dec 04 15:04:59 2020

I tried defining player in an init block, then it caused a problem because it hadn't been defined before the PlayerList() function, so I made one at init -2 and the other init -1 but then I got a really weird error.

I also tried passing the player as an argument in the screen that is using this layered image, but no cigar, just got the exact same error.

Code: Select all

label start_grapple:
    nvl clear
#    "This is the sex scene!"

    hide screen basic_overlay

    show screen grapple_overlay(player=player, npc=npc_dict["npc1"])

Code: Select all

screen grapple_overlay(player, npc):
    #layer "overlay2"

    ## Ensure this appears on top of other screens.
    zorder 2
    add "gui/overlay/grapple_overlay.png"

    frame:

        xalign 0.0
        yalign 0.0
        xsize 543
        yfill True

        background None

        add "protag_grapple" xalign 0.0
Any ideas on why this is happening and what I can do to fix this? Thank you!
Last edited by noeinan on Sat Dec 05, 2020 12:51 am, edited 1 time in total.
Image

Image
Image

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

Re: Layered Image Not Accepting Class Variables...

#2 Post by hell_oh_world »

I believe that this is because layeredimages are read at different offset I think. Also, it's best to default your variables instead of declaring them inside a label etc. That way you can avoid `undefined variable` exceptions etc.
Try that first. If it didn't work, try to also play with offset.

Code: Select all

init 999: # higher means it has a low priority, negative (-999) it will be prioritized first, etc. you can learn more about it in the docs.
  layeredimage...

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Layered Image Not Accepting Class Variables...

#3 Post by noeinan »

Thanks for the help! Unfortunately, defining instead of doing it in the start_label did not change anything. Also, making the layered image init 999 did not fix the error either. I'm really confused about why this is happening!

I feel like I was putting variables after the start label for a reason, like there was some feature or function that required me to do that, but I can't recall off the top of my head.
Image

Image
Image

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
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: Layered Image Not Accepting Class Variables...

#4 Post by Remix »

default player = PlayerList()
Frameworks & Scriptlets:

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Layered Image Not Accepting Class Variables...

#5 Post by noeinan »

I tried that one too but I am still getting the same undefined error. I am not sure what the difference between default and define are, but neither work.
Image

Image
Image

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

Re: Layered Image Not Accepting Class Variables...

#6 Post by hell_oh_world »

i tried just defaulting a variable then using it inside a layeredimage, and it works.
are your variables and layeredimages from different files?
you can try just placing them inside one file, where the variables are above the layeredimages, and see if that works, or renaming their respective files properly and give them a number.
01variables.rpy, 02layeredimages.rpy, etc.

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Layered Image Not Accepting Class Variables...

#7 Post by noeinan »

I do have them in all different files, to keep things organized... Maybe I'll have to put them in the same file but I think that may cause an issue since there's multiple layered images and they're going to be quite big. So if I put literally all of them in the same file, ugh, I feel that will be a nightmare.

I tried numbering the .rpy files but that also didn't fix the issue...
Image

Image
Image

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Layered Image Not Accepting Class Variables...

#8 Post by _ticlock_ »

I also made a quick check with your code. it worked with this:

Code: Select all

init python:
    class PlayerList():
        def __init__(self):
            self.grapple_arms = "tied"

default player = PlayerList()

layeredimage protag_grapple:

    always:
        ...
    if player.grapple_arms == "tied":
        "protag-grapple_arms_tied"
    elif player.grapple_arms == "up":
        "protag-grapple_arms_up"

screen grapple_overlay():
    ...
    add "protag_grapple" xalign 0.0

label start:
    $ player = PlayerList()
    "Line 1"
    show screen grapple_overlay
    "Line 2"
EDIT:

I looked at your error:

Code: Select all

    player.grapple_face = "shock"
NameError: name 'player' is not defined
Where exactly do you have this line player.grapple_face = "shock"?
If it is inside layeredimage you probably meant to write this:

Code: Select all

player.grapple_face == "shock"

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Layered Image Not Accepting Class Variables...

#9 Post by noeinan »

Omg! I didn't notice the error is actually in a different part of the file. It's here:

Code: Select all

init python:
    player.grapple_arms = "up"
    player.grapple_face = "shock"
    player.grapple_legs = "up"

screen grapple_overlay(npc):
    #layer "overlay2"

    ## Ensure this appears on top of other screens.
    zorder 2
    add "gui/overlay/grapple_overlay.png"
I tried making this into an init 1 instead and got the same weird error I got when I tried messing with the init before.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/code/base-player/player-grapple-livecomp.rpy", line 1, in script
    layeredimage protag_grapple:
  File "renpy/common/00layeredimage.rpy", line 779, in execute_layeredimage
    rai.execute()
  File "renpy/common/00layeredimage.rpy", line 771, in execute
    l.extend(i.execute())
  File "renpy/common/00layeredimage.rpy", line 435, in execute
    l.extend(i.execute())
  File "renpy/common/00layeredimage.rpy", line 396, in execute
    return [ Condition(self.condition, eval(self.image), **properties) ]
SyntaxError: unexpected EOF while parsing (game/code/base-player/player-grapple-livecomp.rpy, line 11)

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

Full traceback:
  File "game/code/base-player/player-grapple-livecomp.rpy", line 1, in script
    layeredimage protag_grapple:
  File "E:\_RenPy\renpy-7.3.5-sdk\renpy\ast.py", line 1949, in execute
    self.call("execute")
  File "E:\_RenPy\renpy-7.3.5-sdk\renpy\ast.py", line 1937, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "E:\_RenPy\renpy-7.3.5-sdk\renpy\statements.py", line 277, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/00layeredimage.rpy", line 779, in execute_layeredimage
    rai.execute()
  File "renpy/common/00layeredimage.rpy", line 771, in execute
    l.extend(i.execute())
  File "renpy/common/00layeredimage.rpy", line 435, in execute
    l.extend(i.execute())
  File "renpy/common/00layeredimage.rpy", line 396, in execute
    return [ Condition(self.condition, eval(self.image), **properties) ]
  File "E:\_RenPy\renpy-7.3.5-sdk\renpy\python.py", line 2057, in py_eval
    code = py_compile(code, 'eval')
  File "E:\_RenPy\renpy-7.3.5-sdk\renpy\python.py", line 692, in py_compile
    raise e
SyntaxError: unexpected EOF while parsing (game/code/base-player/player-grapple-livecomp.rpy, line 11)

Windows-8-6.2.9200
Ren'Py 7.3.5.606
 
Fri Dec 04 20:41:45 2020
I also realized I could just delete this init block all together because these are all defined by default in the player class, but... then I again get that EOF error.

I looked at the line where I'm getting the error and it's a "pass" at the end of an else clause. Should I not have this in a layered image? I was taught to always close if clauses with an else, and I want it to do nothing so I put pass there.

Code: Select all

layeredimage protag_grapple:

    #Protagonist Nude Base
    #Arm position

    if player.grapple_arms == "tied":
        "protag-grapple_arms_tied"
    elif player.grapple_arms == "up":
        "protag-grapple_arms_up"
    else:
        pass #this should never happen, let's add an error message later
Image

Image
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Layered Image Not Accepting Class Variables...

#10 Post by noeinan »

Okay, so I just deleted all of my elses and "pass"es and suddenly everything works. I guess I need to ignore the need to close these if clauses and just leave them alone.
Image

Image
Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot]