Duplicate The Main Menu (Screen Undefined??)

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
TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Duplicate The Main Menu (Screen Undefined??)

#1 Post by TheChatotMaestro »

okokok I know this sounds crazy and dumb but bear with me
If I wanted to duplicate the main menu and have a second screen that looked and functioned exactly like the main menu* but was accessed from other points in the game**, what sections of what files would I have to copy and paste, what sections of that code would I have to change to avoid screwing up the whole game, and would having it in its own dedicated .rpy file mess it up entirely? Full disclosure: I haven't tried anything yet, because I'm afraid to totally wreck my code***.

*obviously I'm gonna like change stuff after, otherwise what's the point of having the screen lol. I want to use the main menu as the template before I make it look different and have different buttons and all that jazz, and I figured copying it would be easier for a relative beginner like me than building up a copy from the ground up
**you'll get to it from a button in a screen, not in characters-talking-gameplay, if this makes any difference
***after I post this I'm gonna make a brand new blank project and screw around with it for a while but I'm wholly unconfident in my ability to figure it out by myself
Last edited by TheChatotMaestro on Wed Jan 09, 2019 6:31 pm, edited 1 time in total.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Duplicate The Main Menu

#2 Post by Per K Grok »

TheChatotMaestro wrote: Wed Jan 02, 2019 3:18 pm okokok I know this sounds crazy and dumb but bear with me
If I wanted to duplicate the main menu and have a second screen that looked and functioned exactly like the main menu* but was accessed from other points in the game**, what sections of what files would I have to copy and paste, what sections of that code would I have to change to avoid screwing up the whole game, and would having it in its own dedicated .rpy file mess it up entirely? Full disclosure: I haven't tried anything yet, because I'm afraid to totally wreck my code***.

*obviously I'm gonna like change stuff after, otherwise what's the point of having the screen lol. I want to use the main menu as the template before I make it look different and have different buttons and all that jazz, and I figured copying it would be easier for a relative beginner like me than building up a copy from the ground up
**you'll get to it from a button in a screen, not in characters-talking-gameplay, if this makes any difference
***after I post this I'm gonna make a brand new blank project and screw around with it for a while but I'm wholly unconfident in my ability to figure it out by myself

Open screens.rpy

find 'screen main_menu():'
copy all the script belonging to that screen.

the last lines would be

Code: Select all

style main_menu_version:
    properties gui.text_properties("version")
You can past that in a new document. It should be saved with a .rpy ending and saved in the game folder.

Change the name of the screen i.e. to, 'screen main_menu2():'

The links in the left side box comes from the "screen navigation():' Screen navigation is shown slightly different on the main menu and on other pages, so navigation will be different on the original main menu and your new main menu (2).

An example of a very simple menu page

Code: Select all

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

        vbox:
            text "Trophy 1"
            text "Trophy 2"
            text "Trophy 3"
if you want to open that page from navigation you could add this to the navigation screen

textbutton _("Trophy") action ShowMenu("trophy")

Your idea to have a separate project to test stuff is a very good idea.

I hope this is of some help to you.

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Duplicate The Main Menu

#3 Post by TheChatotMaestro »

Hi!
First off, thank you so much for your help. What I had tested out on my own was very very similar- I had used a different name for the main menu, though. second_menu instead of main_menu(2).
When I use main_menu(2), I get this error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/secondmenu.rpy", line 1: expected 'name' not found.
    screen main_menu(2):
                     ^

Ren'Py Version: Ren'Py 7.1.3.1092
Fri Jan 04 16:15:06 2019
(Instead of a ^, it's got a little red arrow pointing to the 2.)

When I use second_menu, however, I get no error message. I'm cool with no errors happening, I'm just curious as to why this happens and if I'm actually doing stuff wrong.



Secondly, I noticed this line of code in the screens file:

Code: Select all

        if main_menu:

            textbutton _("Start") action Start()
I thought "ok, so that's the code that puts the start button on the main menu. What if I do this?", and changed it to this:

Code: Select all

        if main_menu:

            textbutton _("Start") action Start()
        
        if second_menu:
            
            textbutton _("Start") action Jump(wherever)
The idea being that this second menu will have a 'start' button that will take you somewhere else, almost as if you're making a 'decoy' main menu to trick the player into thinking they're at the real one. (This is not what I'm going to do, but it's a cool application of the idea that I thought of just now and thought might help you understand what I'm going for.) However, when I try to launch the game afterwards, I get this error message:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 356, in execute
    screen main_menu():
  File "game/screens.rpy", line 356, in execute
    screen main_menu():
  File "game/screens.rpy", line 371, in execute
    use navigation
  File "game/screens.rpy", line 292, in execute
    screen navigation():
  File "game/screens.rpy", line 292, in execute
    screen navigation():
  File "game/screens.rpy", line 294, in execute
    vbox:
  File "game/screens.rpy", line 306, in execute
    if second_menu:
NameError: name 'second_menu' is not defined

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

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\ast.py", line 881, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\python.py", line 1913, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
    python hide:
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
    ui.interact()
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\ui.py", line 289, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\core.py", line 2672, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\core.py", line 3059, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\core.py", line 531, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\core.py", line 531, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\core.py", line 531, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\screen.py", line 424, in visit_all
    callback(self)
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\core.py", line 3059, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\screen.py", line 434, in per_interact
    self.update()
  File "C:\Users\Caro\Desktop\renpy-7.1.3-sdk\renpy\display\screen.py", line 619, in update
    self.screen.function(**self.scope)
  File "game/screens.rpy", line 356, in execute
    screen main_menu():
  File "game/screens.rpy", line 356, in execute
    screen main_menu():
  File "game/screens.rpy", line 371, in execute
    use navigation
  File "game/screens.rpy", line 292, in execute
    screen navigation():
  File "game/screens.rpy", line 292, in execute
    screen navigation():
  File "game/screens.rpy", line 294, in execute
    vbox:
  File "game/screens.rpy", line 306, in execute
    if second_menu:
  File "<screen language>", line 306, in <module>
NameError: name 'second_menu' is not defined

Windows-8-6.2.9200
Ren'Py 7.1.3.1092
Test 1.0
Fri Jan 04 16:23:21 2019
And I have no idea what that means. Is this possible? Am I overlooking some other step?

UPDATE!
I tried it out without that part of code that was causing problems, and it worked flawlessly, even when combined with all the other weird code stuff I was going to do to have you get there! This is absolutely fantastic news! However, I noticed that it still has all the same buttons as the main menu- even the one I added to help you get there, so it must still be tagged as a main menu. Does this have anything to do with the "style prefix"? That's still set to "main_menu".
DOUBLE UPDATE: This seems to be the case for the background, as well as the buttons. The three things I want to change are the background, the music, and the buttons. I'll do some research into "style prefix"es, and see if I can work all this out myself.

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Duplicate The Main Menu

#4 Post by TheChatotMaestro »

Ok, I figured out some important things, so I guess it's time to double-post. Super sorry, I just want to make sure I write this down for other people to use and to make sure no one replies with things I already know.

Background
To change the background of the second menu, all I had to do was change a passage in gui.rpy to look like this:

Code: Select all

## Main and Game Menus #########################################################

## The images used for the main and game menus.
define gui.main_menu_background = "gui/main_menu.png"
define gui.second_menu_background = "gui/second_menu.png"
define gui.game_menu_background = "gui/game_menu.png"
And then change my second menu to say this:

Code: Select all


    add gui.second_menu_background
    
instead of main_menu_background.

Music
To change the background music of the new menu, I used this code:

Code: Select all

on "replace" action Play("music", "music/Diamond_Knight.mp3")
Which I figured out from someone else's forum thread. Not sure why the extra "music" is there, but it works, so *shrug*
Question: When I change this to not be classified as the real main menu, there's a button that will probably appear that returns to the main menu. When I do this, will I have to add a line like this to the main menu as well, so it plays the correct music when you return, or does that already happen via Main Menu Magic?

edit: fixed something wrong that i said

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

Re: Duplicate The Main Menu

#5 Post by Imperf3kt »

main_menu(2) doesn't work because anything inside the brackets are parameters.
Use something like main_menu2

Regards the start command, you almost had it right, but you need quotations - ""

Code: Select all

 
        if main_menu:

            textbutton _("Start") action Start()
        
        if second_menu:
            
            textbutton _("Start") action Jump("wherever") 
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

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Duplicate The Main Menu

#6 Post by TheChatotMaestro »

Imperf3kt wrote: Fri Jan 04, 2019 9:23 pm main_menu(2) doesn't work because anything inside the brackets are parameters.
Use something like main_menu2

Regards the start command, you almost had it right, but you need quotations - ""

Code: Select all

 
        if main_menu:

            textbutton _("Start") action Start()
        
        if second_menu:
            
            textbutton _("Start") action Jump("wherever") 
I'm still getting the "name second_menu is not defined" issue :( (It shows up when I try to launch the game, not when I click anything)

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

Re: Duplicate The Main Menu

#7 Post by Imperf3kt »

That's unusual.
And you definitely made a screen called second_menu()?
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

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Duplicate The Main Menu

#8 Post by TheChatotMaestro »

Imperf3kt wrote: Sat Jan 05, 2019 2:15 pm That's unusual.
And you definitely made a screen called second_menu()?
It didn't have the () before, but adding it didn't seem to change anything, and neither did moving it from its own file into the screens file.

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Duplicate The Main Menu

#9 Post by TheChatotMaestro »

Small update on my findings:

The error message obviously tells me that the name isn't defined. However, I have the screen defined in a file of its own. I looked through the screens file, and noticed it started with init offset = -1, while the file I was working with didn't. So, I added it to the top of the file. That didn't change anything. I was like, okay, maybe I have to have it get defined before everything else, so I changed it from -1 to -2. However, when I did that, I got the error accent color is not defined. So that means that it requires some stuff to be defined before it, but that stuff is in the same file as the stuff that has to be defined after it? /ómò\
Moving around code bits and changing up numbers got me nowhere, so I gave up on that.
Putting the second menu back into screens.rpy above the navigation menu screen (instead of below like I had it before) didn't work either, and neither did moving the part where the navigation menu was defined into the same file as the second menu, above or below.
Changing "style_prefix" didn't work at all either, and neither did various other combinations of init and init offset and the like.

I have it defined like this:

Code: Select all

screen second_menu():

    ## This ensures that any other menu screen is replaced.
    tag menu

    style_prefix "main_menu"
    
    on "replace" action Play("music", "music/Diamond_Knight.mp3")
    
    add gui.second_menu_background

    ## This empty frame darkens the main menu.
    frame:
        pass

    ## The use statement includes another screen inside this one. The actual
    ## contents of the main menu are in the navigation screen.
    use navigation

    if gui.show_name:

        vbox:
            text "[config.name!t]":
                style "main_menu_title"

            text "[config.version]":
                style "main_menu_version"


style main_menu_frame is empty
style main_menu_vbox is vbox
style main_menu_text is gui_text
style main_menu_title is main_menu_text
style main_menu_version is main_menu_text

style main_menu_frame:
    xsize 280
    yfill True

    background "gui/overlay/main_menu.png"

style main_menu_vbox:
    xalign 1.0
    xoffset -20
    xmaximum 800
    yalign 1.0
    yoffset -20

style main_menu_text:
    properties gui.text_properties("main_menu", accent=True)

style main_menu_title:
    properties gui.text_properties("title")

style main_menu_version:
    properties gui.text_properties("version")
There's been no changes except changing lots of 'main' to 'second', and I've made sure to change it everywhere it's referenced to. I've tried all sorts of different names for this menu, to see if it was a problem with the name of the screen, but none are working. Where do I need to put this code so it will resolve after the things it needs to create itself, but before the navigation screen? Am I thinking about this all wrong- is the problem something totally different than what I'm expecting? Should I just start over, and create the code from scratch, so there's nothing tying it down to the main menu except visual resemblance? \;^;/

The next thing I am going to try is changing up all those styles- first, deleting where they are defined a second time, and if that doesn't work, I will try redefining them so they are style second_menu_frame, etc.

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

Re: Duplicate The Main Menu

#10 Post by Imperf3kt »

At a glance, seems okay.
I did notice this.

Code: Select all

style main_menu_frame:
    xsize 280
    yfill True

    background "gui/overlay/main_menu.png"
This is what styles the frames in the main menu. The background attribute here is for the frame, but it looks like you are trying to use the main menu overlay background which might result in some odd looking frames.

If you already have these styles in the main menu, there is no need to duplicate them in the new menu you are making, that's what the style prefix is for.
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

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Duplicate The Main Menu

#11 Post by TheChatotMaestro »

Imperf3kt wrote: Mon Jan 07, 2019 4:43 pm At a glance, seems okay.
I did notice this.

Code: Select all

style main_menu_frame:
    xsize 280
    yfill True

    background "gui/overlay/main_menu.png"
This is what styles the frames in the main menu. The background attribute here is for the frame, but it looks like you are trying to use the main menu overlay background which might result in some odd looking frames.

If you already have these styles in the main menu, there is no need to duplicate them in the new menu you are making, that's what the style prefix is for.
That's weird, that's copied straight from the original main menu screen. Ren'py uses that image for the frame by default.

Removed the redundant definitions, screen still "undefined" though.

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Duplicate The Main Menu (Screen Undefined??)

#12 Post by TheChatotMaestro »

Update to this thread after over a year:

I removed the problematic button from the navigation screen (if second_menu: // textbutton _("Start") action Jump("wherever") ).
I then duplicated the navigation screen, added a button that called the first main menu, and set the second_menu screen to "use second_navigation". I also removed a bunch of game_menu stuff from second_navigation, since it's only used for that main menu.

Works fine. Not sure why I didn't think of this before. Hope this helps someone :D

Post Reply

Who is online

Users browsing this forum: Andredron, geoWaffle, Google [Bot]