Prevent clicking during dialogue?

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
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Prevent clicking during dialogue?

#1 Post by Offworlder » Sat Jan 05, 2019 12:57 pm

I apologize for asking a thousand questions lately. I'm actually working on a birthday present, so time is not on my side. x_x;

What I'm trying to figure out is a way to disable clicking before a block of dialogue finishes. I do want the dialogue to stop at the end so the player can click to the next screen when ready, I just don't want the player to have the option of clicking prematurely (which forces the current block of dialogue to finish immediately).

This isn't something I'd do under normal circumstances, because it's something I usually don't appreciate having to deal with myself. However, the game I'm currently working on is meant to simulate that MC is conversing directly with PLAYER. The speed of MC's dialogue ebbs and flows in as natural a way as I could manage, and skipping ahead would undoubtedly ruin that effect. This game is only meant for a person whom I'm positive won't mind the proposed restriction.

Any and all suggestions would be greatly appreciated!
Last edited by Offworlder on Sat Jan 05, 2019 1:43 pm, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Preventing clicking during dialogue?

#2 Post by Alex » Sat Jan 05, 2019 1:20 pm

Well, you can disable the player's ability to click through the dialog, but don't forget to make a kind of autoforward through the lines.

Not tested, but try

Code: Select all

screen stop_scr():
    key "dismiss" action [[]]

label start:
    "Let's begin."
    "Now you can skip the dialog by clicking..."
    show screen stop_scr
    "And now you are not...*green*{w=2.0}{nw}"
    "You'l have to read this carefully.{w=2.0}{nw}"
    "Hope this would be interesting for you...{w=2.0}{nw}"
    "So, the message is ... ...{w=2.0}{nw}"
    hide screen stop_scr
    "That's it - you can go on clicking, if you like."
    "?"
https://www.renpy.org/doc/html/text.htm ... -text-tags
https://www.renpy.org/doc/html/screens.html
https://www.renpy.org/doc/html/screens.html#key

User avatar
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Re: Preventing clicking during dialogue?

#3 Post by Offworlder » Sat Jan 05, 2019 1:48 pm

Alex wrote:
Sat Jan 05, 2019 1:20 pm
Well, you can disable the player's ability to click through the dialog, but don't forget to make a kind of autoforward through the lines.
I may be misunderstanding, but I believe your suggestion is for preventing the player from clicking forward on their own at all? That is, the dialogue would continue automatically after a pre-determined length of time. Without pausing in-between lines for a manual click.

If so, that's no quite what I had in mind! Though I realized my description wasn't very clear. I just want to disable the ability to stop lines of dialogue from playing at their intended speed. I do still want the player to click to the next screen once the dialogue finishes, though. Just not press a button to finish the dialogue early.

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

Re: Prevent clicking during dialogue?

#4 Post by Imperf3kt » Sat Jan 05, 2019 2:19 pm

You could place a blank screen that has modal True and a timer. The screen dissappears once the timer ends (you'd have to adjust the timer for all the dialogue you plan to use it with)

This is probably a terrible way of doing it, but it's the only way I can currently think of.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

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: Prevent clicking during dialogue?

#5 Post by trooper6 » Sat Jan 05, 2019 4:51 pm

There is a fairly easy way to do this, using character callbacks and config.say_allow_dismiss. I do a version of this for my game. I can explain, but you'll have to give me a few hours as I'm about to GM an RPG on Twitch and I won't be able to put a simple code example together until after I'm done.
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
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Re: Prevent clicking during dialogue?

#6 Post by Offworlder » Sat Jan 05, 2019 9:43 pm

Imperf3kt wrote:
Sat Jan 05, 2019 2:19 pm
You could place a blank screen that has modal True and a timer. The screen dissappears once the timer ends (you'd have to adjust the timer for all the dialogue you plan to use it with)

This is probably a terrible way of doing it, but it's the only way I can currently think of.
That'd be pretty impractical, since I plan on doing this with every line of dialogue in the game. x_x

User avatar
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Re: Prevent clicking during dialogue?

#7 Post by Offworlder » Sat Jan 05, 2019 9:45 pm

trooper6 wrote:
Sat Jan 05, 2019 4:51 pm
There is a fairly easy way to do this, using character callbacks and config.say_allow_dismiss. I do a version of this for my game. I can explain, but you'll have to give me a few hours as I'm about to GM an RPG on Twitch and I won't be able to put a simple code example together until after I'm done.
That sounds promising! I look forward to your explanation. ^-^
I hope your stream is going/went well!

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: Prevent clicking during dialogue?

#8 Post by trooper6 » Sun Jan 06, 2019 1:25 am

So I while back, I created a project that goes through all the different ways you can block dismissal. I did this because everyone always wants to block dismissal. So here is a my tutorial code that talks about all the different ways to do it.

Make a brand new project, and make this code your script.rpy. Then play the project while you follow along with the code.

Code: Select all

# You can place the script of your game in this file.

# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"

# Declare characters used by this game.
define a = Character(None, kind=nvl, color="#c8ffc8", what_slow_cps=20, slow_abortable=False, what_xalign=0.5, window_xalign=0.5, what_yalign=0.5, window_yalign=0.5)
define b = Character(None, kind=nvl, color="#c8ffc8", what_slow_cps=20, slow_abortable=False, what_xalign=0.5, window_xalign=0.5, what_yalign=0.5, window_yalign=0.5, callback=nogo)   

init: 
    style nvl_vbox: #This allows you to place NVL text to be centered on both the x axis and the y axis if you want
        xfill True
        yfill True
        
# The game starts here.
label start:
    "First things first. Make sure you are following along with the actual code in your text editor while you run the program."
    "There are multiple ways to block dismissing."
    "I'll try to keep all the code relevant to each option all next to each other."
    "Lastly, since I think the OP wants something that looks like a credit sequence that auto forwards without clicking, 
     I'm going to try and model that, though all the techniques I'm talking about can be used in different circumstances with 
     small changes."
    "Let's begin."
    menu choices:
        "Which option would you like to check out?"
        "Hard Pauses and Text Displayables":
            jump hardpauses
        "Using _dismiss_pause and Text Displayables":
            jump dispause
        "Using a screen to block dismissing":
            jump nodis_screen
        "Using say_allow_dismiss manually":
            jump nodis_func
        "Character Callback Triggering say_allow_dismiss":
            jump nodis_callback
        "Only advance by clicking a button":
            jump nodis_button
        "All Done":
            pass
    "Your Tester is done."
    "But remember! PyTom says blocking dismissal is a) user unfriendly and b) might make the user think the game has crashed."
    "So really think about if you want to actually do it."
    return
    

#####
#Hard Pauses and Text Displayables
#####

#Here we define our text as displables
image end1 = Text("And so the ranch was saved from the Wiplash Gang.", slow=True, slow_cps=20)
image end2 = Text("Jane Barkley became the mayor of the town.", slow=True, slow_cps=20)
image end3 = Text("Chet Li became the new Law Keeper.", slow=True, slow_cps=20)
image end4 = Text("And everyone lived happily ever after.", slow=True, slow_cps=20)

label hardpauses:
    scene black
    "Here, we are showing text displayables using transitions. This could also be other animations."
    "Becasue we are doing this, Hard Pauses are the way to go!"
    "Try to click through while the text is being shown."
    
    show end1 at truecenter
    $renpy.pause(4.0, hard=True)
    hide end1
    show end2 at truecenter
    $renpy.pause(4.0, hard=True)
    hide end2
    show end3 at truecenter
    $renpy.pause(4.0, hard=True)
    hide end3
    show end4 at truecenter
    $renpy.pause(4.0, hard=True)
    hide end4
    
    "You shouldn't have been able to click through."
    "That is how hard pauses with text displayables work."
            
    "Using hard pauses is a thing for stopping people clicking through your animations."
    "Of course, you have to know how long your animations are."
    jump choices
    
#####
# _dismiss_pause and Text Displayables
#####

#Here we define our text as displables
image end1 = Text("And so the ranch was saved from the Wiplash Gang.", slow=True, slow_cps=20)
image end2 = Text("Jane Barkley became the mayor of the town.", slow=True, slow_cps=20)
image end3 = Text("Chet Li became the new Law Keeper.", slow=True, slow_cps=20)
image end4 = Text("And everyone lived happily ever after.", slow=True, slow_cps=20)

label dispause:
    scene black
    "Here, we are showing text displayables using transitions. This could also be other animations."
    "Rather than Hard Pauses, you can set the _dismiss_pause variable to False and block dismissal that way."
    "This seems the more grown up way to do this."
    "Try to click through while the text is being shown."
    
    $_dismiss_pause = False
    show end1 at truecenter
    pause 4.0
    hide end1
    show end2 at truecenter
    pause 4.0
    hide end2
    show end3 at truecenter
    pause 4.0
    hide end3
    show end4 at truecenter
    pause 4.0
    hide end4
    
    "You shouldn't have been able to click through."
    "That is how using _dismiss_pause with text displayables work."
            
    "Using hard pauses is a thing for stopping people clicking through your animations."
    "Of course, you have to know how long your animations are."
    $_dismiss_pause = True
    jump choices
    

#####
#Using a Screen to block dismissal
#####

screen nodismiss(): #Our screen, while it is visible, no one can dismiss anything at all
    key "dismiss" action NullAction()
    
label nodis_screen:
    scene black
    "With this option you are using an NVL character who talks slowly...though it could be an ADV character as well."
    "To stop the user from being able to stop the slow talking, the character has slow_abortable False."
    "To stop the user from being able to click through, show a screen that doesn't allow for any sorts of dismissing."
    
    show screen nodismiss
    a "And so the ranch was saved from the Wiplash Gang.{p=1.0}{nw}"
    nvl clear
    a "Jane Barkley became the mayor of the town.{p=1.0}{nw}"
    nvl clear
    a "Chet Li became the new Law Keeper.{p=1.0}{nw}"
    nvl clear
    a "And everyone lived happily ever after.{p=1.0}{nw}"
    nvl clear
    hide screen nodismiss  
    
    "You shouldn't have been able to click through."
    "That is how using a screen to block dismissing works."
    "As long as your nodis_screen is up, there will be no dismissing of anything."
    "But note! We had to hide that screen right away, or you wouldn't have been able to click through any of this text either!"
    "With that screen up we could have shown a menu, but...after we chose something we wouldn't be able to continue on."
    "So on to other options."

    jump choices
  
  
#####
#Manually using the say_allow_dismiss config variable
#####

default can_cont = True #The variable that will determine if we can dismiss or not
    
init -1 python:
    def dis_block(): #This is the funciton that returns our variable
        global can_cont
        return can_cont
    config.say_allow_dismiss = dis_block #This tells the computer to check our function to see if dismissing is allowed.
    
label nodis_func:
    "Renpy also has a config variable called config.say_allow_dismiss."
    "What it does is run a function. If the function returns True, it allows you to dismiss a say statement. If it returns False, it doesn't."
    "So to use this, you need a function that returns either True or False based on if you want the text to be able to be dismissed."
    "I find the easiest thing to do is have a variable, in our case 'can_cont'. Then I make a funciton dis_block that returns that variable."
    "If I want to stop dismissal, I turn can_cont False. If I want dismissing to be okay, I turn can_cont True."
    "Like so..."
    
    $ can_cont = False
    a "And so the ranch was saved from the Wiplash Gang.{p=1.0}{nw}"
    nvl clear
    a "Jane Barkley became the mayor of the town.{p=1.0}{nw}"
    nvl clear
    a "Chet Li became the new Law Keeper.{p=1.0}{nw}"
    nvl clear
    a "And everyone lived happily ever after.{p=1.0}{nw}"
    nvl clear
    $ can_cont = True  
    
    "You shouldn't have been able to click through."
    "That is how you manually stop dismissing using the say_allow_dismiss config variable."
    "I had to turn it off because otherwise, you wouldn't be able to click through this text either."
    "As long as con_cont is false, there will be no dismissing."
  
    jump choices


#####
#Trigger the say_allow_dismiss config variable function using character callbacks.
#####

#default can_cont = True #The variable that will determine if we can dismiss or not
    
#init -1 python:
#    def dis_block(): #This is the funciton that returns our variable
#        global can_cont
#        return can_cont
#    config.say_allow_dismiss = dis_block #This tells the computer to check our function to see if dismissing is allowed.
    
init -1 python:
    def nogo(event, **kwargs): #This is the character call back we give our character b. While B is talking, it can't be dismissed.
        global can_cont
        if event == "show" or event == "begin":
            can_cont = False
        if event == "slow_done" or event == "end":
            can_cont = True
            
label nodis_callback:
    "Another option is to give specific characters a callback that automatically stops dismissal when they are talking 
     and turns dismissal back on when they finish talking."
    "Why would you do that?" 
    "Well for my game, there is only one character whose dialoge I want to be unskippable (without pressing a button). 
     The other character is totally fine to be skipped through."
    "Remember that you have to make sure the character has the callback on them when you define them...see character b at the top."
    "Also, we are using the can_cont variable and the dis_block function and the config.say_allow_dismiss from the Manual section 
     if you were to only use this option in your game, you'd want to uncomment the commented out repeated code in this section."
    "Here we go..."
    
    b "And so the ranch was saved from the Wiplash Gang."
    nvl clear
    b "Jane Barkley became the mayor of the town."
    nvl clear
    b "Chet Li became the new Law Keeper."
    nvl clear
    b "And everyone lived happily ever after."
    nvl clear
    
    "You shouldn't have been able to click through while the character was talking but should be able to once the text finished."
    "That is how you automatically stop dismissing using the say_allow_dismiss confic variable and a character callback."
    "The cool thing about that is that you can make it character specific."

    jump choices
    
#####
#Only allowing dismissal by pressing a button and the Menu Problem
#####

default is_menu = False

screen nodismiss2(): #Our screen, while it is visible, no one can dismiss anything at all
    key "dismiss" action NullAction()
    textbutton "Dismiss" action Return("smth")
    #textbutton "Dismiss" action If(is_menu, NullAction(), Return("smth"))
    
#init -1 python:
#    def menu(items): #Custom menu that turns off the ability to forward while menu is up
#        renpy.hide_screen("nodismiss2")
#        choice_made=renpy.display_menu(items)        
#        renpy.show_screen("nodismiss2")
#        return choice_made #return the choice
        
#    def menu(items): #Custom menu that turns off the ability to forward while menu is up
#        global is_menu
#        is_menu = True
#        choice_made=renpy.display_menu(items)  
#        is_menu = False
#        return choice_made #return the choice
    
label nodis_button:
    scene black
    "With this option you are using an NVL character who talks slowly."
    "You also have a screen that disables all dismissal, but a button on that screen that will allow you to dismiss instead."
    "Why would you do this? I did this because I wanted that dismiss button to have a few other functions as well, such as 
     tracking how often the text was dismissed."
    "To stop the user from being able to stop the slow talking, the character has slow_abortable False."
    "To stop the user from being able to click through, show a screen that doesn't allow for any sorts of dismissing."
    "To have the button forward, you give it the action Return('smth')"
    "I'd like you to go through this particular option four times."
    
    "First time through. Just go through it and press a menu button not the dismiss button when the menu shows up."
    
    "Second time through, press the dismiss button rather than a menu button when the menu shows up."
    "This should give you an error. This is because the menu is expecting to get a number that represents the choice made, 
     but it is getting the string 'smth' instead."
    "So what do you do?"
    "You have a couple options, I'll give you two of them."
    
    "Third time through uncomment the init -1 python line and the first def menu(items) function above."
    "What that function does is it hides the nodismiss2 screen so that you can't press that button, it takes your menu choice,
     it makes the screen visible again and then returns the menu choice to the menu."
    "Try that out."
    
    "But what if you want the button and screen to remain visible the entire time?"
    "In that case, comment out the first menu function and uncomment the second menu function. Also, comment out the first 
     textbutton and uncomment the second textbutton."
    "With this option the textbutton checks our variable is_menu. If is_menu is True, then the dismiss button doesn't do anything. 
     If is_menu is False, then it returns 'smth'. So that second function? when the menu is called, it makes is_menu True thu making 
     the textbutton useless. Right before it returns the menu choice it turn the is_menu function back to False, thus activating 
     the textbutton again."
    "Try that out."
    
    show screen nodismiss2()
    a "And so the ranch was saved from the Wiplash Gang."
    nvl clear
    a "Jane Barkley became the mayor of the town."
    nvl clear
    a "Chet Li became the new Law Keeper."
    nvl clear
    a "And everyone lived happily ever after."
    nvl clear
    
    "You shouldn't have been able to click through. You can't click through this either without clicking the Dismiss button."
    "That is how using a screen to block dismissing works with a dismiss button."
    
    "This is our menu that I want you to go through four different times to see how it works."
    menu:
        "What do you want for breakfast?"
        "Eggs":
            "Eggs are tasty."
        "Toast":
            "Toast...don't you want more?"
        "French Toast":
            "Eggs and Toast together! Yay"

    hide screen nodismiss2
    "That is what you need to know about blocking dismissal except for a button."
    jump choices

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
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Re: Prevent clicking during dialogue?

#9 Post by Offworlder » Sun Jan 06, 2019 10:01 am

trooper6 wrote:
Sun Jan 06, 2019 1:25 am
So I while back, I created a project that goes through all the different ways you can block dismissal. I did this because everyone always wants to block dismissal. So here is a my tutorial code that talks about all the different ways to do it.
You are an absolute lifesaver and all-around amazing human being for creating this! Seriously, everything was so easy to follow and the examples were perfect. I thought I'd done something wrong and the code wasn't working at first, but then I remembered that part of the dialogue didn't have a defined character attached to it. xD;

It was easy to just make a third defined character with a blank name, then attach your statements to it. Everything is now working flawlessly!
Thanks a ton for your help here, and for making such a useful tool that has and will undoubtedly benefit tons of developers!

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: Prevent clicking during dialogue?

#10 Post by trooper6 » Sun Jan 06, 2019 12:30 pm

No worries at all!

When working on my project I tried out lots of different ways of blocking input and considering how often people ask, I just made that tutorial so other people could see the ways I found.
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

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot