How can I make a out-game menu that can conditionally show texts and images?

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
apoto
Newbie
Posts: 22
Joined: Thu Apr 26, 2018 11:32 am
Contact:

How can I make a out-game menu that can conditionally show texts and images?

#1 Post by apoto »

I was in the middle of making a crime visual novel, and I need to add a "evidence" menu to show all the evidences the POV has collected.
But when I tried to use the "if" sentence, it generated a traceback file and didn't work
Can somebody please help me?

Code: Select all

screen exhibit():
    tag menu
    use game_menu(_("Codex"), scroll="viewport"):

        style_prefix "codex"

        has vbox:
            spacing 20

        if  testflag2 = True:
             label "a"
             text _("a")

Code: Select all

I'm sorry, but an uncaught exception occurred.

After initialization, but before game start.
  File "game/screens.rpy", line 728, in analyze_screen
    screen exhibit():
  File "game/screens.rpy", line 728, in analyze
    screen exhibit():
  File "game/screens.rpy", line 728, in analyze
    screen exhibit():
  File "game/screens.rpy", line 730, in analyze
    use game_menu(_("Codex"), scroll="viewport"):
  File "game/screens.rpy", line 730, in analyze
    use game_menu(_("Codex"), scroll="viewport"):
  File "game/screens.rpy", line 734, in analyze
    has vbox:
  File "game/screens.rpy", line 734, in analyze
    has vbox:
  File "game/screens.rpy", line 739, in analyze
    if  testflag2 = True:
SyntaxError: invalid syntax (game/screens.rpy, line 739)

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

Full traceback:
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\bootstrap.py", line 306, in bootstrap
    renpy.main.main()
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\main.py", line 513, in main
    run(restart)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\main.py", line 82, in run
    renpy.display.screen.analyze_screens()
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\screen.py", line 870, in analyze_screens
    s.ast.analyze_screen()
  File "game/screens.rpy", line 728, in analyze_screen
    screen exhibit():
  File "game/screens.rpy", line 728, in analyze
    screen exhibit():
  File "game/screens.rpy", line 728, in analyze
    screen exhibit():
  File "game/screens.rpy", line 730, in analyze
    use game_menu(_("Codex"), scroll="viewport"):
  File "game/screens.rpy", line 730, in analyze
    use game_menu(_("Codex"), scroll="viewport"):
  File "game/screens.rpy", line 734, in analyze
    has vbox:
  File "game/screens.rpy", line 734, in analyze
    has vbox:
  File "game/screens.rpy", line 739, in analyze
    if  testflag2 = True:
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\pyanalysis.py", line 529, in is_constant_expr
    node, literal = ccache.ast_eval_literal(expr)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\pyanalysis.py", line 683, in ast_eval_literal
    expr = py_compile(expr, 'eval', ast_node=True)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\python.py", line 674, in py_compile
    raise e
SyntaxError: invalid syntax (game/screens.rpy, line 739)

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: How can I make a out-game menu that can conditionally show texts and images?

#2 Post by philat »

Code: Select all

if testflag2:

User avatar
erickcire95
Regular
Posts: 33
Joined: Tue Dec 26, 2017 7:38 pm
Contact:

Re: How can I make a out-game menu that can conditionally show texts and images?

#3 Post by erickcire95 »

The problem is that you are using a single "=", this is used only to set someting, if you are checking for equalty then you should use double, i.e: "=="

Code: Select all

if  testflag2 == True:
However, if you are just checking for True/False, it's a bit simpler to just omit the equal part.

Code: Select all

screen exhibit():
    tag menu
    use game_menu(_("Codex"), scroll="viewport"):

        style_prefix "codex"

        has vbox:
            spacing 20

        if  testflag2:
             label "a"
             text _("a")

User avatar
apoto
Newbie
Posts: 22
Joined: Thu Apr 26, 2018 11:32 am
Contact:

Re: How can I make a out-game menu that can conditionally show texts and images?

#4 Post by apoto »

erickcire95 wrote: Thu Apr 26, 2018 10:48 pm The problem is that you are using a single "=", this is used only to set someting, if you are checking for equalty then you should use double, i.e: "=="

Code: Select all

if  testflag2 == True:
However, if you are just checking for True/False, it's a bit simpler to just omit the equal part.

Code: Select all

screen exhibit():
    tag menu
    use game_menu(_("Codex"), scroll="viewport"):

        style_prefix "codex"

        has vbox:
            spacing 20

        if  testflag2:
             label "a"
             text _("a")

Thank you for your generous reply, however after trying this code, the game crashed after clicking the menu button.
related code:

Code: Select all

label start:

$ Testflag = False
$ Testflag2 = False

Code: Select all

screen evidence():
    tag menu
    use game_menu(_("evidence"), scroll="viewport"):

        style_prefix "evidence"

        has vbox:
            spacing 20
              label "a"
        if  Testflag2:
             label "a"
             text _("a")



define gui.evidence = ""


style evidence_label is gui_label
style evidence_label_text is gui_label_text
style evidence_text is gui_text

style evidence_label_text:
    size gui.label_text_size
the crash report

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "game/screens.rpy", line 728, in execute
    screen evidence():
  File "game/screens.rpy", line 728, in execute
    screen evidence():
  File "game/screens.rpy", line 730, in execute
    use game_menu(_("证物"), scroll="viewport"):
  File "game/screens.rpy", line 422, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 422, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 431, in execute
    frame:
  File "game/screens.rpy", line 434, in execute
    hbox:
  File "game/screens.rpy", line 440, in execute
    frame:
  File "game/screens.rpy", line 443, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 445, in execute
    viewport:
  File "game/screens.rpy", line 454, in execute
    vbox:
  File "game/screens.rpy", line 455, in execute
    transclude
  File "game/screens.rpy", line 730, in execute
    use game_menu(_("证物"), scroll="viewport"):
  File "game/screens.rpy", line 734, in execute
    has vbox:
  File "game/screens.rpy", line 737, in execute
    if  testflag2:
NameError: name 'Testflag2' is not defined

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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\ast.py", line 862, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\python.py", line 1888, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\core.py", line 2635, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\core.py", line 3019, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\screen.py", line 420, in visit_all
    callback(self)
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\core.py", line 3019, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\screen.py", line 430, in per_interact
    self.update()
  File "H:\fdl\renpy-6.99.14.3-sdk\renpy\display\screen.py", line 611, in update
    self.screen.function(**self.scope)
  File "game/screens.rpy", line 728, in execute
    screen evidence():
  File "game/screens.rpy", line 728, in execute
    screen evidence():
  File "game/screens.rpy", line 730, in execute
    use game_menu(_("证物"), scroll="viewport"):
  File "game/screens.rpy", line 422, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 422, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 431, in execute
    frame:
  File "game/screens.rpy", line 434, in execute
    hbox:
  File "game/screens.rpy", line 440, in execute
    frame:
  File "game/screens.rpy", line 443, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 445, in execute
    viewport:
  File "game/screens.rpy", line 454, in execute
    vbox:
  File "game/screens.rpy", line 455, in execute
    transclude
  File "game/screens.rpy", line 730, in execute
    use game_menu(_("evidence"), scroll="viewport"):
  File "game/screens.rpy", line 734, in execute
    has vbox:
  File "game/screens.rpy", line 737, in execute
    if  testflag2:
  File "<screen language>", line 737, in <module>
NameError: name 'Testflag2' is not defined

Windows-8-6.2.9200
Ren'Py 6.99.14.3.3347
tarven 0.1
Fri Apr 27 12:15:03 2018

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: How can I make a out-game menu that can conditionally show texts and images?

#5 Post by Remix »

Use

default Testflag2 = True

outside of any label or screen rather than $ Testflag2 = True inside a label
Frameworks & Scriptlets:

User avatar
apoto
Newbie
Posts: 22
Joined: Thu Apr 26, 2018 11:32 am
Contact:

Re: How can I make a out-game menu that can conditionally show texts and images?

#6 Post by apoto »

Thank you all for the great help!

Post Reply

Who is online

Users browsing this forum: Google [Bot]