Unlockable Main Menu button problem [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
MoonByte
Regular
Posts: 165
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Unlockable Main Menu button problem [SOLVED]

#1 Post by MoonByte » Sun May 16, 2021 3:56 pm

It is probably simple, but I am really bad with programming (and more than grateful for this forum for having like 5 million guides and such) and the suggestions I've seen float around about unlocking image buttons don't work (probably all basic issues), but are also all quite old already, so I rather make a new one than revive.

So I essentially have two stories, A and B
A is available from the start and when done, you unlock B.
I have this in script

Code: Select all

init:
    $ persistent.black = False 
And at the end of A, I do

Code: Select all

$ persistent.black = True
And then, in my custom main menu, I have it set up with imagebuttons like this:

Code: Select all

## Main Menu screen ############################################################
##
## Used to display the main menu when Ren'Py starts.
##
## https://www.renpy.org/doc/html/screen_special.html#main-menu

screen main_menu():

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

    style_prefix "main_menu"

    add gui.main_menu_background

    # Image button code
    imagebutton auto "gui/menu/white_%s.png" xpos 40 ypos 110 focus_mask True action Jump("white1x0")
    if persistent.black == True:
        imagebutton auto "gui/menu/black_%s.png" xpos 1100 ypos 110 focus_mask True action Jump("black1x0")
    else:
        imagebutton auto "gui/menu/black_ground.png" xpos 1100 ypos 110 focus_mask True
    imagebutton auto "gui/menu/load_%s.png" xpos 748 ypos 800 focus_mask True action ShowMenu('load')
    imagebutton auto "gui/menu/settings_%s.png" xpos 748 ypos 893 focus_mask True action ShowMenu('preferences')
    imagebutton auto "gui/menu/quit_%s.png" xpos 748 ypos 980 focus_mask True action Quit(confirm=False)
    imagebutton auto "gui/menu/about_%s.png" xpos 1500 ypos 1000 focus_mask True action ShowMenu('about')
    imagebutton auto "gui/menu/help_%s.png" xpos 1700 ypos 1000 focus_mask True action ShowMenu('help')
And well, I get errors and while I know that it is the if-statement (cause just having the imagebutton makes the menu appear and work normally), I don't know how it should look to work.
Last edited by MoonByte on Sun May 16, 2021 4:39 pm, edited 1 time in total.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1077
Joined: Tue Aug 23, 2016 10:35 am
Skype: miinipaa
Contact:

Re: Unlockable Main Menu button

#2 Post by Ocelot » Sun May 16, 2021 4:03 pm

1) Remove

Code: Select all

init:
    $ persistent.black = False 
It will reset variable value each time you start the game, which is probably not what you want.

2) if persistent.black == True:if persistent.black:
No need to tautologically compare boolean variable to boolean variable. condition is already implicitely tested for True.

3) It would be really helpful if you posted actual error. Because there are no problems in if statement, but there is an error in imagebutton definition.
This imagebutton auto "gui/menu/black_ground.png" is wrong. auto property requres string argument to have sibstitution marker %s somewhere in it.
< < insert Rick Cook quote here > >

User avatar
MoonByte
Regular
Posts: 165
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Unlockable Main Menu button problem

#3 Post by MoonByte » Sun May 16, 2021 4:05 pm

Ah, my bad!
With the two changes you said, the error is this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 353, in execute
    screen main_menu():
  File "game/screens.rpy", line 353, in execute
    screen main_menu():
  File "game/screens.rpy", line 364, in execute
    if persistent.black:
  File "game/screens.rpy", line 367, in execute
    imagebutton auto "gui/menu/black_ground.png" xpos 1100 ypos 110 focus_mask True
  File "renpy/common/00defaults.rpy", line 139, in _imagemap_auto_function
    rv = auto_param % variant
TypeError: not all arguments converted during string formatting

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

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "renpy/ast.py", line 922, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2218, in py_exec_bytecode
    exec(bytecode, 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 "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3101, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3512, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/core.py", line 567, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 567, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 567, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/screen.py", line 432, in visit_all
    callback(self)
  File "renpy/display/core.py", line 3512, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/screen.py", line 443, in per_interact
    self.update()
  File "renpy/display/screen.py", line 631, in update
    self.screen.function(**self.scope)
  File "game/screens.rpy", line 353, in execute
    screen main_menu():
  File "game/screens.rpy", line 353, in execute
    screen main_menu():
  File "game/screens.rpy", line 364, in execute
    if persistent.black:
  File "game/screens.rpy", line 367, in execute
    imagebutton auto "gui/menu/black_ground.png" xpos 1100 ypos 110 focus_mask True
  File "renpy/ui.py", line 952, in _imagebutton
    idle = choice(idle, idle_image, "idle", required=True)
  File "renpy/ui.py", line 940, in choice
    rv = renpy.config.imagemap_auto_function(auto, name)
  File "renpy/common/00defaults.rpy", line 139, in _imagemap_auto_function
    rv = auto_param % variant
TypeError: not all arguments converted during string formatting

Windows-10-10.0.19041
Ren'Py 7.4.4.1439
Graphic Test 1.0
Sun May 16 22:04:51 2021
As said, without that if-statement, the menu works perfectly fine :/

Also, what do you mean with the auto-thing? Like, should auto get taken out of all or just the "inactive" button?
Cause when I take it away from the inactive button, 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/screens.rpy", line 367: expected a keyword argument, colon, or end of line.
    imagebutton "gui/menu/black_ground.png" xpos 1100 ypos 110 focus_mask True
                
Ren'Py Version: Ren'Py 7.4.4.1439
Sun May 16 22:08:53 2021

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1077
Joined: Tue Aug 23, 2016 10:35 am
Skype: miinipaa
Contact:

Re: Unlockable Main Menu button problem

#4 Post by Ocelot » Sun May 16, 2021 4:15 pm

MoonByte wrote:
Sun May 16, 2021 4:05 pm
As said, without that if-statement, the menu works perfectly fine :/
If statement itself is fine. The problem is the code for inactive button. If you remove if statement and replace it with code of inactive button, you will get the same problem. Error message even tell you the line where problem heppened:

Code: Select all

  File "game/screens.rpy", line 367, in execute
    imagebutton auto "gui/menu/black_ground.png" xpos 1100 ypos 110 focus_mask True
auto is a replacement for writing ton of individual properties manually. It works by replacing %s in argument by corresponding property names and looking for these images. If you use auto, then the string you give must contain %s. Otherwise you will need to manually set button properties you need. You probably want insensitive property here.

More info on imagebutton properties:
https://www.renpy.org/doc/html/screens.html#imagebutton
< < insert Rick Cook quote here > >

User avatar
MoonByte
Regular
Posts: 165
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Unlockable Main Menu button problem

#5 Post by MoonByte » Sun May 16, 2021 4:39 pm

Ah ok, I misunderstood what you meant with the auto comment, my bad.

Code: Select all

if persistent.black == True:
        imagebutton auto "gui/menu/black_%s.png" xpos 1100 ypos 110 focus_mask True action Jump("black1x0")
    else:
        imagebutton auto "gui/menu/black_%s.png" xpos 1100 ypos 110 focus_mask True
This version works (it doesn't use the insensitive graphic, but I can live with that). Thanks Ocelot!
Last edited by MoonByte on Sun May 16, 2021 4:46 pm, edited 1 time in total.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1077
Joined: Tue Aug 23, 2016 10:35 am
Skype: miinipaa
Contact:

Re: Unlockable Main Menu button problem [SOLVED]

#6 Post by Ocelot » Sun May 16, 2021 4:44 pm

If you want, you can get rid of if statement and make your button conditionally sensivive:
imagebutton auto "gui/menu/black_%s.png" xpos 1100 ypos 110 focus_mask True action Jump("black1x0") sensitive persistent.black
< < insert Rick Cook quote here > >

User avatar
MoonByte
Regular
Posts: 165
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

Re: Unlockable Main Menu button problem [SOLVED]

#7 Post by MoonByte » Sun May 16, 2021 4:46 pm

Ooooh, that looks at least much nicer!
Thank you!

P.S.
In case anyone here is looking for help, I noticed one small thing: do NOT use "Jump" in it. Use Start(label name). Or you play the game IN the main menu :'D

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

Re: Unlockable Main Menu button problem [SOLVED]

#8 Post by Imperf3kt » Sun May 16, 2021 5:19 pm

Just to point out, the variable "black" is already defined internally within renpy as a variable (hex colour #000)
Though it shouldn't affect persistent.black
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Latest Blackjack updates

Post Reply

Who is online

Users browsing this forum: Google [Bot]