[SOLVED]Chapter selection - 'Locked chapter imagebutton' HELP!

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
Sterkiherz
Regular
Posts: 87
Joined: Wed Oct 03, 2018 6:16 pm
Projects: Comic: Miraclewish; Visual Novel: Murder Mystery Ghost Story (WIP)
Organization: Sterki Herz
Tumblr: sterkiherz
itch: sterkiherz
Discord: sterkiherz#7005
Contact:

[SOLVED]Chapter selection - 'Locked chapter imagebutton' HELP!

#1 Post by Sterkiherz »

Hi! How is it going?
I found myself stuck when trying to do some coding on imagebuttons and I thought that maybe asking for some help could be right thing to do. :?

I know that maybe it is something not really complicated but since I am not a programmer, I can't really make it work the way I want it to.
I apologize if what i am asking is a bit too silly but i just don't know what to do! >.<

So I've been working on a Visual Novel and I decided to add a screen where you can choose which chapter to read. What I want to do is that if the player hasn't seen the chapter already, the button that says 'Chapter 2' will be locked. And as soon as they read this particular chapter in the game, and they go back to this screen the button is now sensitive.

I managed to acomplish this somehow but when the button is locked, instead of showing the 'insensitive' image i made, it becomes invisible.
It works perfectly but my problem is that, as I said, i would like it to actually show but you can't click on it until you 'unlock' the chapter.

This is how my screen looks like:
Image
  • The button that says 'Chapter 1': Idle image
  • The button that says 'Chapter 2': Hover image
  • The button that says 'Chapter 3, 4, and so on': Insensitive image

And this is the code I am using for this screen:
[*]Init

Code: Select all

   
#---check for unlocked chapters---    
    $ persistent.ch1 = False  
    $ persistent.ch2 = False 
    $ persistent.ch3 = False 
    $ persistent.ch4 = False 
    $ persistent.ch5 = False 
    $ persistent.ch6 = False 
[*]Chapter Selection Screen

Code: Select all

#---- Chapter Select screen ----
screen chapters():
    tag menu
    #tooltip
    default ta = Tooltip(None)
    default td = Tooltip(None)
    default te = Tooltip(None)
    default tf = Tooltip(None)
    
    add "ch_bg.png"

    #chapters ##BUTTONS DISSAPEAR WHEN CH IS FALSE. I WANT THEM TO SHOW AS INSENSITIVE INSTEAD.
    if persistent.ch1:                                                                                               
        imagebutton auto "ch1_%s.png" xpos 354 ypos 48 focus_mask None action Start('ch1') hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    if persistent.ch2:
        imagebutton auto "ch2_%s.png" xpos 354 ypos 158 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    if persistent.ch3:
        imagebutton auto "ch3_%s.png" xpos 354 ypos 268 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    if persistent.ch4:
        imagebutton auto "ch4_%s.png" xpos 354 ypos 378 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    if persistent.ch5:
        imagebutton auto "ch5_%s.png" xpos 354 ypos 488 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    if persistent.ch6:
        imagebutton auto "ch6_%s.png" xpos 354 ypos 598 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    
    #other
    imagebutton auto "back_%s.png" xpos 1134 ypos 592 focus_mask None action ShowMenu('menulobby') hovered td.Action('ch_back_info.png') activate_sound "select.wav" hover_sound "cursor8.wav"
    imagebutton auto "next_%s.png" xpos 1024 ypos 324 focus_mask None action Null hovered te.Action('ch_page_info.png') activate_sound "select.wav" hover_sound "cursor8.wav"
    imagebutton auto "prev_%s.png" xpos 96 ypos 324 focus_mask None action Null hovered te.Action('ch_page_info.png') activate_sound "select.wav" hover_sound "cursor8.wav"
    
    add ta.value xpos 5 ypos 615
    add td.value xpos 5 ypos 615
    add te.value xpos 5 ypos 615
    add tf.value xpos 5 ypos 615 #show only when ch is not unlocked and 'chapter locked' button is being hovered (ch_unlock_info.png)
[*]When the player reads a chapter

Code: Select all

label ch1:
    #Unlocks chapter1
    $ persistent.ch1 = True
    ...
Also, I am using tooltips that appear when a button is hovered. I would like one to appear when the insensitive button is being hovered telling the player that they need to unlock that chapter first. If it is not possible, is there any other way i can do that?

Oh! I almost forget! I am using renpy's latest version.

I hope someone can help me :<
Last edited by Sterkiherz on Tue Oct 23, 2018 7:53 am, edited 1 time in total.
Image
๐“Ÿ๐“ธ๐“ป๐“ฝ๐“ฏ๐“ธ๐“ต๐“ฒ๐“ธ โœฆ ๐“๐“ป๐“ฝ ๐“‘๐“ต๐“ธ๐“ฐ โœฆ ๐““๐“ฒ๐“ผ๐“ฌ๐“ธ๐“ป๐“ญ (sterkiherz#7005) โœฆ sterki.herz@gmail.com
~~Feel free to contact me for any questions~~
๏ธตโ€ฟ๏ธตโ€ฟเญจโ™กเญงโ€ฟ๏ธตโ€ฟ๏ธต
๐ป๐“Š๐‘”๐“ˆ & ๐’ฆ๐’พ๐“ˆ๐“ˆ๐‘’๐“ˆ, ๐’ฎ๐“‰๐‘’๐“‡๐“€๐’พ ๐ป๐‘’๐“‡๐“

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

Re: Chapter selection - 'Locked chapter imagebutton' HELP!

#2 Post by philat »

Code: Select all

action [Start('ch1', SensitiveIf(persistent.ch1)]

User avatar
Sterkiherz
Regular
Posts: 87
Joined: Wed Oct 03, 2018 6:16 pm
Projects: Comic: Miraclewish; Visual Novel: Murder Mystery Ghost Story (WIP)
Organization: Sterki Herz
Tumblr: sterkiherz
itch: sterkiherz
Discord: sterkiherz#7005
Contact:

Re: Chapter selection - 'Locked chapter imagebutton' HELP!

#3 Post by Sterkiherz »

philat wrote: โ†‘Mon Oct 22, 2018 9:12 pm

Code: Select all

action [Start('ch1', SensitiveIf(persistent.ch1)]
Hi :3
Thank you so much for your reply, but as soon as I put that in my imagebutton code there was an error :(
First it was a syntax error because it needed another ")". But when i fixed that, this error came up:

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/script.rpy", line 133, in execute
    screen chapters():
  File "game/script.rpy", line 133, in execute
    screen chapters():
  File "game/script.rpy", line 145, in execute
    imagebutton auto "ch1_%s.png" xpos 354 ypos 48 focus_mask None action [Start('ch1', SensitiveIf(persistent.ch1))] hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
  File "game/script.rpy", line 145, in keywords
    imagebutton auto "ch1_%s.png" xpos 354 ypos 48 focus_mask None action [Start('ch1', SensitiveIf(persistent.ch1))] hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
TypeError: __init__() takes at most 2 arguments (3 given)

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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\ast.py", line 882, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\python.py", line 1913, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\ui.py", line 289, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\core.py", line 2662, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\core.py", line 3049, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\core.py", line 521, in visit_all
    d.visit_all(callback, seen)
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\core.py", line 521, in visit_all
    d.visit_all(callback, seen)
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\core.py", line 521, in visit_all
    d.visit_all(callback, seen)
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\core.py", line 521, in visit_all
    d.visit_all(callback, seen)
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\screen.py", line 424, in visit_all
    callback(self)
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\core.py", line 3049, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\screen.py", line 434, in per_interact
    self.update()
  File "D:\Ciin\CINTHIA\renpy\renpy-7.1.0-sdk\renpy\display\screen.py", line 619, in update
    self.screen.function(**self.scope)
  File "game/script.rpy", line 133, in execute
    screen chapters():
  File "game/script.rpy", line 133, in execute
    screen chapters():
  File "game/script.rpy", line 145, in execute
    imagebutton auto "ch1_%s.png" xpos 354 ypos 48 focus_mask None action [Start('ch1', SensitiveIf(persistent.ch1))] hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
  File "game/script.rpy", line 145, in keywords
    imagebutton auto "ch1_%s.png" xpos 354 ypos 48 focus_mask None action [Start('ch1', SensitiveIf(persistent.ch1))] hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
  File "<screen language>", line 145, in <module>
TypeError: __init__() takes at most 2 arguments (3 given)

Windows-8-6.2.9200
Ren'Py 7.1.0.882
Sample Project 1.0
Mon Oct 22 23:13:08 2018
Do you know how to fix this? or did I write it wrong?
Image
๐“Ÿ๐“ธ๐“ป๐“ฝ๐“ฏ๐“ธ๐“ต๐“ฒ๐“ธ โœฆ ๐“๐“ป๐“ฝ ๐“‘๐“ต๐“ธ๐“ฐ โœฆ ๐““๐“ฒ๐“ผ๐“ฌ๐“ธ๐“ป๐“ญ (sterkiherz#7005) โœฆ sterki.herz@gmail.com
~~Feel free to contact me for any questions~~
๏ธตโ€ฟ๏ธตโ€ฟเญจโ™กเญงโ€ฟ๏ธตโ€ฟ๏ธต
๐ป๐“Š๐‘”๐“ˆ & ๐’ฆ๐’พ๐“ˆ๐“ˆ๐‘’๐“ˆ, ๐’ฎ๐“‰๐‘’๐“‡๐“€๐’พ ๐ป๐‘’๐“‡๐“

User avatar
Sterkiherz
Regular
Posts: 87
Joined: Wed Oct 03, 2018 6:16 pm
Projects: Comic: Miraclewish; Visual Novel: Murder Mystery Ghost Story (WIP)
Organization: Sterki Herz
Tumblr: sterkiherz
itch: sterkiherz
Discord: sterkiherz#7005
Contact:

Re: Chapter selection - 'Locked chapter imagebutton' HELP!

#4 Post by Sterkiherz »

I added that in my first imagebutton to test it:

Code: Select all

screen chapters():
    tag menu
    #tooltip
    default ta = Tooltip(None)
    default td = Tooltip(None)
    default te = Tooltip(None)
    default tf = Tooltip(None)
    
    add "ch_bg.png"

    #chapters ##BUTTONS DISSAPEAR WHEN CH IS FALSE. I WANT THEM TO SHOW AS INSENSITIVE INSTEAD.
    #if persistent.ch1:  
    imagebutton auto "ch1_%s.png" xpos 354 ypos 48 focus_mask None action [Start('ch1', SensitiveIf(persistent.ch1))] hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    #if persistent.ch2:
    imagebutton auto "ch2_%s.png" xpos 354 ypos 158 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    #if persistent.ch3:
    imagebutton auto "ch3_%s.png" xpos 354 ypos 268 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    #if persistent.ch4:
    imagebutton auto "ch4_%s.png" xpos 354 ypos 378 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    #if persistent.ch5:
    imagebutton auto "ch5_%s.png" xpos 354 ypos 488 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    #if persistent.ch6:
    imagebutton auto "ch6_%s.png" xpos 354 ypos 598 focus_mask None action Null hovered ta.Action('ch_info.png')  activate_sound "select.wav" hover_sound "cursor8.wav"
    
    #other
    imagebutton auto "back_%s.png" xpos 1134 ypos 592 focus_mask None action ShowMenu('menulobby') hovered td.Action('ch_back_info.png') activate_sound "select.wav" hover_sound "cursor8.wav"
    imagebutton auto "next_%s.png" xpos 1024 ypos 324 focus_mask None action Null hovered te.Action('ch_page_info.png') activate_sound "select.wav" hover_sound "cursor8.wav"
    imagebutton auto "prev_%s.png" xpos 96 ypos 324 focus_mask None action Null hovered te.Action('ch_page_info.png') activate_sound "select.wav" hover_sound "cursor8.wav"
    
    add ta.value xpos 5 ypos 615
    add td.value xpos 5 ypos 615
    add te.value xpos 5 ypos 615
    add tf.value xpos 5 ypos 615 #solo para cuando el boton de ch no esta activo, ya q no se desbloqueo el capitulo. (ch_unlock_info.png)
Image
๐“Ÿ๐“ธ๐“ป๐“ฝ๐“ฏ๐“ธ๐“ต๐“ฒ๐“ธ โœฆ ๐“๐“ป๐“ฝ ๐“‘๐“ต๐“ธ๐“ฐ โœฆ ๐““๐“ฒ๐“ผ๐“ฌ๐“ธ๐“ป๐“ญ (sterkiherz#7005) โœฆ sterki.herz@gmail.com
~~Feel free to contact me for any questions~~
๏ธตโ€ฟ๏ธตโ€ฟเญจโ™กเญงโ€ฟ๏ธตโ€ฟ๏ธต
๐ป๐“Š๐‘”๐“ˆ & ๐’ฆ๐’พ๐“ˆ๐“ˆ๐‘’๐“ˆ, ๐’ฎ๐“‰๐‘’๐“‡๐“€๐’พ ๐ป๐‘’๐“‡๐“

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Chapter selection - 'Locked chapter imagebutton' HELP!

#5 Post by trooper6 »

Try it like so:

Code: Select all

action [Start('ch1'), SensitiveIf(persistent.ch1)]
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Sterkiherz
Regular
Posts: 87
Joined: Wed Oct 03, 2018 6:16 pm
Projects: Comic: Miraclewish; Visual Novel: Murder Mystery Ghost Story (WIP)
Organization: Sterki Herz
Tumblr: sterkiherz
itch: sterkiherz
Discord: sterkiherz#7005
Contact:

Re: Chapter selection - 'Locked chapter imagebutton' HELP!

#6 Post by Sterkiherz »

trooper6 wrote: โ†‘Mon Oct 22, 2018 11:39 pm Try it like so:

Code: Select all

action [Start('ch1'), SensitiveIf(persistent.ch1)]
IT WORKED! 8)

Thank you so much to both of you!
Image
๐“Ÿ๐“ธ๐“ป๐“ฝ๐“ฏ๐“ธ๐“ต๐“ฒ๐“ธ โœฆ ๐“๐“ป๐“ฝ ๐“‘๐“ต๐“ธ๐“ฐ โœฆ ๐““๐“ฒ๐“ผ๐“ฌ๐“ธ๐“ป๐“ญ (sterkiherz#7005) โœฆ sterki.herz@gmail.com
~~Feel free to contact me for any questions~~
๏ธตโ€ฟ๏ธตโ€ฟเญจโ™กเญงโ€ฟ๏ธตโ€ฟ๏ธต
๐ป๐“Š๐‘”๐“ˆ & ๐’ฆ๐’พ๐“ˆ๐“ˆ๐‘’๐“ˆ, ๐’ฎ๐“‰๐‘’๐“‡๐“€๐’พ ๐ป๐‘’๐“‡๐“

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]