[SOLVED] Text-based interaction: can't get screens to work

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
jdlang
Newbie
Posts: 13
Joined: Wed Mar 22, 2017 2:59 pm
Contact:

[SOLVED] Text-based interaction: can't get screens to work

#1 Post by jdlang »

I'm trying to make an interface for text-based interaction with the player's environment. It's supposed to show the scene's background and scrollable text boxes with textbuttons representing all NPCs and objects players can interact with, jumping to the appropriate label when clicked. I want to keep it modular, so I can define the labels and names when needed, not having to hardcode separate screens for every interaction hub.

To this end, I've tried making an example interaction hub, cannibalizing the tutorial game's selection screen, changing everything I have a rough idea about, and figuring it out from there. Problem is, as soon as the game gets to the point where it has to show the screens, it gives an error. To be frank, I don't have any idea how most of the code actually works, and I'm having trouble understanding the documentation.

The screens:

Code: Select all

screen look:

    side "tl":
        area (250, 40, 548, 400)

        viewport:
            yadjustment adj
            mousewheel True

            vbox:
                for label, name in look:
                    textbutton name.caption:
                        action Return(label)

                null height 20

        bar adjustment adj style "vscrollbar"
        
screen talk:

    side "c l":
        area (250, 40, 548, 400)

        viewport:
            yadjustment adj
            mousewheel True

            vbox:
                for label, name in look:
                    textbutton name.caption:
                        action Return(label)

                null height 20
        bar adjustment adj style "vscrollbar"
The label:

Code: Select all

label council_intro01_look_nexus:

    init python:

        look = [
            ("council_intro01_look_statue", _("statue")),
            ("council_intro01_look_gothicbuilding", _("gothic building")),
            ]
            
        talk = [
            ("council_intro01_talk_sam", _("Sam")),
            ]
    
    call screen look
    
    call screen talk
    
    $ renpy.pause(hard=True)
The traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script_council_intro.rpy", line 101, in script
    call screen look
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "game/customscreens.rpy", line 1, in execute
    screen look:
  File "game/customscreens.rpy", line 1, in execute
    screen look:
  File "game/customscreens.rpy", line 3, in execute
    side "tl":
  File "game/customscreens.rpy", line 6, in execute
    viewport:
  File "game/customscreens.rpy", line 6, in keywords
    viewport:
NameError: name 'adj' is not defined

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

Full traceback:
  File "game/script_council_intro.rpy", line 101, in script
    call screen look
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\ast.py", line 1706, in execute
    self.call("execute")
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\ast.py", line 1724, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\statements.py", line 145, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\exports.py", line 2526, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\ui.py", line 285, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\display\core.py", line 2538, in interact
    scene_lists.replace_transient()
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\display\core.py", line 822, in replace_transient
    self.remove(layer, tag)
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\display\core.py", line 1107, in remove
    self.hide_or_replace(layer, remove_index, "hide")
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\display\core.py", line 1031, in hide_or_replace
    d = oldsle.displayable._hide(now - st, now - at, prefix)
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\display\screen.py", line 443, in _hide
    self.update()
  File "C:\renpy1\renpy-6.99.12.4-sdk\renpy\display\screen.py", line 578, in update
    self.screen.function(**self.scope)
  File "game/customscreens.rpy", line 1, in execute
    screen look:
  File "game/customscreens.rpy", line 1, in execute
    screen look:
  File "game/customscreens.rpy", line 3, in execute
    side "tl":
  File "game/customscreens.rpy", line 6, in execute
    viewport:
  File "game/customscreens.rpy", line 6, in keywords
    viewport:
  File "<screen language>", line 7, in <module>
NameError: name 'adj' is not defined
I've tried commenting out the adjustment thing, but that just results in a jump to the next item on the list of errors. I'm kinda out of my depth here.
Sorry for this noob crap. Any help is appreciated.
Last edited by jdlang on Mon Mar 27, 2017 3:32 pm, edited 1 time in total.

User avatar
jdlang
Newbie
Posts: 13
Joined: Wed Mar 22, 2017 2:59 pm
Contact:

Re: Text-based interaction: can't get screens to work

#2 Post by jdlang »

Alright! After a lot of trial and error, I've gotten it to work. Lesson learned: if possible, try writing code from scratch instead of copypasting code written by someone who (unlike me) knows what they're doing.
I'll post the code for anyone with a similar problem, but I still have a question. There are still things in there I don't understand, and I've amputated anything from the original that gave me an error, mostly without replacement. Is there anything in there that might come back and bite me in the ass later on? Can you think of a more elegant way to write this? Thanks!

Edit: Encountered a bug. Putting the look and talk containers in init python makes it impossible to change them from within the game. Using python instead fixes that. Updated the code.

Edit2: This seems to be working fine. I'll mark the thread as solved.

Anyway, here's the code.

Screens:

Code: Select all

screen look:

    text "look at" pos(100, 70)

    side "c l":
        area (100, 100, 300, 200)

        viewport:
            mousewheel True
            scrollbars "vertical"

            vbox:
                for name, label in look:
                    textbutton str(name):
                        action Jump(label)

                null height 20
        
screen talk:

    text "talk to" pos(100, 470)

    side "c l":
        area (100, 500, 300, 200)

        viewport:
            mousewheel True
            scrollbars "vertical"

            vbox:
                for name, label in talk:
                    textbutton str(name):
                        action Jump(label)

                null height 20
Showing the screens in a label and feeding them options:

Code: Select all

label council_intro01_look_nexus:

    python:

        look = [
            (_("statue"), _("council_intro01_look_statue")),
            (_("gothic building"), _("council_intro01_look_gothicbuilding")),
            ]
            
        talk = [
            (_("Sam"), _("council_intro01_talk_sam")),
            ]
    
    show screen look
    
    show screen talk
    
    $ renpy.pause(hard=True)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Majestic-12 [Bot]