'main_menu' special label

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
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

'main_menu' special label

#1 Post by zmook »

The docs say:
main_menu
If it exists, this label is called instead of the main menu. If it returns, Ren'Py will start the game at the start label. For example, the following will immediately start the game without displaying the main menu.

Code: Select all

label main_menu:
    return
This seems appealing as a debugging shortcut, but I'm wary if sticking in debug code that I can't automatically disable with a config variable. I mean, I've forgotten to remove debug code before and I'm sure I'll do it again.

Is there any way to do this conditionally, based on something like a `debug` boolean? I mean, this doesn't work:

Code: Select all

label main_menu if debug:
    return
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: 'main_menu' special label

#2 Post by Imperf3kt »

The condition config.developer should do what you need.

Code: Select all

label main_menu:
    if config.developer:
        return
    else:
        pass
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: 'main_menu' special label

#3 Post by zmook »

The `debug` variable is not my problem. The problem is that if I return, it goes to the 'start' label. If I don't return, it falls through to the next label in the script (which also happens to be 'start', though it could be anything). For this to work, I need something that conditionally disables the *existence* of the 'main_menu' label. Or else, more likely, some other way to conditionally bypass the main menu on game startup.

This pseudocode:

Code: Select all

if debug:
	skip main menu
else:
	show main menu normally
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

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

Re: 'main_menu' special label

#4 Post by hell_oh_world »

I would suggest using the `splashcreen` label instead, then add `$ renpy.run(Start())` as the last line of that label. Then add whatever condition you want on when to run this action.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: 'main_menu' special label

#5 Post by Imperf3kt »

zmook wrote: Thu Feb 25, 2021 8:27 pm The `debug` variable is not my problem. The problem is that if I return, it goes to the 'start' label. If I don't return, it falls through to the next label in the script (which also happens to be 'start', though it could be anything). For this to work, I need something that conditionally disables the *existence* of the 'main_menu' label. Or else, more likely, some other way to conditionally bypass the main menu on game startup.

This pseudocode:

Code: Select all

if debug:
	skip main menu
else:
	show main menu normally
In that case, maybe replace "pass" in my psuedocode example from above with a jump to a dummy label that then returns? In theory it should get you out of the stack depth, back to main menu context.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: 'main_menu' special label

#6 Post by zmook »

hell_oh_world wrote: Thu Feb 25, 2021 8:56 pm I would suggest using the `splashcreen` label instead, then add `$ renpy.run(Start())` as the last line of that label. Then add whatever condition you want on when to run this action.
Hm. That throws an exception.

Code: Select all

label splashscreen:

    if debug: 
        $ renpy.run(Start())
    return

Code: Select all

While running game code:
  File "renpy/common/00start.rpy", line 231, in script call
    call _splashscreen from _call_splashscreen_1
  File "game/script.rpy", line 5, in script
    $ renpy.run(Start())
  File "game/script.rpy", line 5, in <module>
    $ renpy.run(Start())
  File "renpy/common/00action_menu.rpy", line 148, in __call__
    renpy.jump_out_of_context(self.label)
JumpOutException: start
I also just tried putting code into the main_menu screen itself to see if I could just trigger the action like an automated click. This also does not work:

Code: Select all

screen main_menu():

    tag menu

    python:
        if debug: 
            renpy.run(Start())

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 36, in script call
    call time_controller from _call_time_controller
  File "game/time_controller.rpy", line 7, in script
    "Time controller"
Exception: ui.interact called with non-empty widget/layer stack. Did you forget a ui.close() somewhere?
Stack was <Layer: u'transient'>
<Many: <Fixed at 1122f1f10>>
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: 'main_menu' special label

#7 Post by zmook »

Imperf3kt wrote: Thu Feb 25, 2021 10:07 pm In that case, maybe replace "pass" in my psuedocode example from above with a jump to a dummy label that then returns? In theory it should get you out of the stack depth, back to main menu context.
Jumping to a dummy label and then returning has the same effect as returning directly. It appears that the docs should just say: "If the label 'main_menu' exists, it will be called instead of the screen 'main_menu'. When it returns Ren'Py will start the game at the start label."

Aha! this seems to work, then:

Code: Select all

label main_menu:
    if debug:
        return
    else:
        call screen main_menu()
    return
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: Bing [Bot]