replacing preferences bar with +/- textbuttons

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
morg
Regular
Posts: 95
Joined: Sun May 10, 2015 7:35 am
Projects: Cupid's Affair
Tumblr: n-morg
Contact:

replacing preferences bar with +/- textbuttons

#1 Post by morg » Sat Jul 02, 2016 1:04 pm

what I want to do is replace the volume bars with '+' and '-' text buttons. You click on them to adjust the volume rather then sliding the bar.

I have this piece of code:

Code: Select all

            frame:
                style_group "pref"
                has hbox

                label _("Text Speed")
                textbutton _("+") action SetVariable("text speed", text speed +1)
                text "[text speed]"
                textbutton _("-") action SetVariable("text speed", text speed -1)
but it keeps giving me this:

Code: Select all

  File "game/screens.rpy", line 372, in prepare
    textbutton _("+") action SetVariable("text speed", text speed +1)
  File "game/screens.rpy", line 372, in prepare
    textbutton _("+") action SetVariable("text speed", text speed +1)
SyntaxError: invalid syntax (game/screens.rpy, line 372)
I'm guessing it's because there's a spacebar between text and speed? Because I tried it with another variable and it worked. Or did I just get the name wrong?
thanks in advance :)
Image

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: replacing preferences bar with +/- textbuttons

#2 Post by chocoberrie » Sat Jul 02, 2016 1:49 pm

You could use imagebuttons instead of text buttons! The cool thing about imagebuttons is you can make two images, one with a + sign on it and one with a - sign on it, and use those two images as clickable buttons.

Here's an example, where the + button is plus_tspeed.png and the - button is minus_tspeed.png. You can adjust their position on the screen using xpos and ypos. The action for the + button would be to increase the text speed, and the action for the - button would be to decrease the text speed.

Code: Select all

screen preferences:
    tag menu    # This ensures that any other menu screen is replaced.
    add "BACKGROUND IMAGE FILE NAME HERE"    # Background image for the prefs menu
    use navigation    # Include the navigation.

# Text speed buttons
    imagebutton auto "plus_tspeed.png" xpos 475 ypos 190 focus_mask True action _______
    imagebutton auto "minus_tspeed.png" xpos 475 ypos 190 focus_mask True action ______
You can use the following action in place of the ______ line:

Code: Select all

Preference("text speed", ###)
So your code would look like this:

Code: Select all

screen preferences:
    tag menu    # This ensures that any other menu screen is replaced.
    add "BACKGROUND IMAGE FILE NAME HERE"    # Background image for the prefs menu
    use navigation    # Include the navigation.

# Text speed buttons
    imagebutton auto "plus_tspeed.png" xpos 475 ypos 190 focus_mask True action Preference("text speed", ###)
    imagebutton auto "minus_tspeed.png" xpos 475 ypos 190 focus_mask True action Preference("text speed", ###)
Replace ### with the speed you want. E.g. Putting 142 would make the text appear at a rate of 142 characters per second. (I found this action code in this list of screen actions in the Ren'Py documentation!)

Since you want to be able to increase and decrease the text speed, remember that the number you put instead of ### in the above code would basically be an increment. Clicking the + button would increase the text speed by that specific amount (and vice versa for the - button), so you don't want the number to be too high.

I hope this helps! :D

User avatar
morg
Regular
Posts: 95
Joined: Sun May 10, 2015 7:35 am
Projects: Cupid's Affair
Tumblr: n-morg
Contact:

Re: replacing preferences bar with +/- textbuttons

#3 Post by morg » Sun Jul 03, 2016 3:40 pm

thanks for your help!
well I used the imagebutton and it gave me a few problems so I reverted to textbutton and it worked nicely,
Image
using

Code: Select all

screen preferences:
    tag menu    # This ensures that any other menu screen is replaced.
    # Background image for the prefs menu
    use navigation    # Include the navigation.
    frame:
        vbox xalign 0.3 yalign 0.3:
            text "text speed" size 48 color "#fee3ed" outlines [(4, "fff", 0, 0), (3, "#B9B0D9", 0, 0)]
            hbox xalign 0.3 yalign 0.3:
                textbutton "+" action Preference("text speed", +1)
                textbutton "-" action Preference("text speed", -1)
but there's one more thing I'd like to do; which is display the text speed between the + and - to clear things up for the player. but when I write

Code: Select all

text "[text speed]"
it gives me the error;

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 337, in execute
    screen preferences:
  File "game/screens.rpy", line 341, in execute
    frame:
  File "game/screens.rpy", line 342, in execute
    vbox xalign 0.3 yalign 0.3:
  File "game/screens.rpy", line 344, in execute
    hbox xalign 0.3 yalign 0.3:
  File "game/screens.rpy", line 346, in execute
    text "[text speed]"
KeyError: 'text speed'
So I guess I got the variable name wrong? which one do I use to display the text speed?
Image

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: replacing preferences bar with +/- textbuttons

#4 Post by chocoberrie » Sun Jul 03, 2016 4:07 pm

Good to hear! :)

Ah, I see what you mean, you'd like to display the actual text speed in number form? I think this could be done with another textbutton, and you could fiddle with xpos and ypos for all three buttons (the + sign, the - sign, and the text speed) to position them the way you want.

Unfortunately, I'm not sure of the code you'd need to show the actual text speed... Let me look around and see if I can find something! In the meantime, maybe someone else here on the forums would know? :)

User avatar
morg
Regular
Posts: 95
Joined: Sun May 10, 2015 7:35 am
Projects: Cupid's Affair
Tumblr: n-morg
Contact:

Re: replacing preferences bar with +/- textbuttons

#5 Post by morg » Mon Jul 04, 2016 12:22 pm

yep, that's exactly what i'm trying to do! does anyone here know the code for that? :)
Image

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

Re: replacing preferences bar with +/- textbuttons

#6 Post by chocoberrie » Mon Jul 04, 2016 1:25 pm

Hmmm... Well, I know that config.default_text_cps in options.rpy is responsible for telling Ren'py what the default text speed is of all text in the dialogue box is.

According to the Ren'Py documentation (see here):
Ren'Py Documentation wrote:

Code: Select all

config.default_text_cps = 0

(This is the default speed, with 0 being the fastest, and 1 being the slowest)

Replace 0 with the number of characters that should be shown per second. Valid numbers are in the range 1-100, with 0 being special-cased as infinite speed. (Note that this is somewhat odd... 0 is infinitely fast, 1 is very slow, and 100 is very fast.)

To make this setting take effect, close Ren'Py, delete game/saves/persistent, and then re-launch your game.
I'm not exactly sure how you can show the current text_cps as actual text... Maybe putting text_cps in quotes as a part of the textbutton? I don't really know XD

Code: Select all

textbutton "text_cps"
(I don't think this would work, since text_cps is a variable and not a string...)

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: replacing preferences bar with +/- textbuttons

#7 Post by namastaii » Mon Jul 04, 2016 2:21 pm

I tested out "[text_cps]" and it returns an error. This might be really hard to achieve actually lol

If you end up not figuring it out or it's just too much trouble (especially to increment text speed by 1 when there are a lot of numbers, it could end up being tedious to the player) what I would do is create like 3 buttons with slow, medium, and fast (or something along those lines) and have each of those pick a number with a slow-ish speed, medium, then fast speed. But that's just an idea.

User avatar
morg
Regular
Posts: 95
Joined: Sun May 10, 2015 7:35 am
Projects: Cupid's Affair
Tumblr: n-morg
Contact:

Re: replacing preferences bar with +/- textbuttons

#8 Post by morg » Tue Jul 05, 2016 7:05 pm

that's actually a really good idea! assuming that the maximum is 142, one could set the slow to 15, the medium to 40 and the fast to 80. this may not be suitable for players who like to adjust things to precision. nevertheless, if anyone wants to use this they can feel free to.
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: replacing preferences bar with +/- textbuttons

#9 Post by namastaii » Tue Jul 05, 2016 7:18 pm

Yeah, I mean me personally, I wouldn't care to increment the speed by 1 with a button over and over to figure out how fast I want it. Just having a couple of preset options would be quick and easy in my opinion.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], _ticlock_