Toggle Quick menu Text to Quick menu ICONS

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
Yuvan raj
Regular
Posts: 32
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Toggle Quick menu Text to Quick menu ICONS

#1 Post by Yuvan raj » Sun Feb 21, 2021 11:40 am

Hello friends, I'm just starting renpy and I want to give players options to use icons for quickmenu instead of text like these. Image
This is my code to add the icons in quick menu with the if statement without any conditions. I don't know what conditions to use.Image
And this is my code for the Preference screen.
Image
I have this on the preference screen.
Image
I request you guys to let me know how I can turn it on and off to switch between the quick menu Text and quick menu icons.
Thank you

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

Re: Toggle Quick menu Text to Quick menu ICONS

#2 Post by Imperf3kt » Sun Feb 21, 2021 4:20 pm

I suggest you use the action ToggleVariable() on your button.
For the variable name, make sure you append the suffix persistent. to it

So for example
action ToggleVariable("persistent.q_menu_style")

Don't forget to default the variable outside a label.
default persistent.q_menu_style = True # or False, either will work.

Then in your quick menu screen, simply check the variable and use either the textbutton, or your icons (probably as imagebuttons)


If you post your code instead of screenshots, I could write you out an example - not right now though as I haven't got the time.


Note that this will only toggle the variable - if you want two separate buttons, you'd use SetVariable()


Further examples can be found in my free Android GUI linked in my signature, but its not particularly beginner ready yet.
Last edited by Imperf3kt on Sun Feb 21, 2021 6:42 pm, edited 3 times in total.
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

User avatar
zmook
Regular
Posts: 170
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Toggle Quick menu Text to Quick menu ICONS

#3 Post by zmook » Sun Feb 21, 2021 4:21 pm

1. Somewhere in your options, add this:

Code: Select all

default persistent.quick_icons = True
2. In your preferences screen, add this:

Code: Select all

                    textbutton _("Use Icons") action ToggleVariable("persistent.quick_icons")
3. in the quick_menu `if`, use `if persistent.quick_icons:`
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Yuvan raj
Regular
Posts: 32
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Re: Toggle Quick menu Text to Quick menu ICONS

#4 Post by Yuvan raj » Mon Feb 22, 2021 5:16 am

Imperf3kt wrote:
Sun Feb 21, 2021 4:20 pm
I suggest you use the action ToggleVariable() on your button.
For the variable name, make sure you append the suffix persistent. to it

So for example
action ToggleVariable("persistent.q_menu_style")

Don't forget to default the variable outside a label.
default persistent.q_menu_style = True # or False, either will work.

Then in your quick menu screen, simply check the variable and use either the textbutton, or your icons (probably as imagebuttons)


If you post your code instead of screenshots, I could write you out an example - not right now though as I haven't got the time.


Note that this will only toggle the variable - if you want two separate buttons, you'd use SetVariable()


Further examples can be found in my free Android GUI linked in my signature, but its not particularly beginner ready yet.
Thank you so much for the clear explanation. i made it work! Again Thank you.
I have one doubt though. This is my preference screen code
Image
And this is my
Image
I have to use 'if not' which I think means, by default the persistent. quick_icon is False and when I click it it becomes true. And since it is true textbutton is I use only 'if' then textbutton is displayed. I can use 'if not' or just swap the textbutton and imagebutton lines. But how to change it so that by default the persistent.quick_icon is True and when I click the button it becomes False and so if I use if then it won't be displayed?
I hope you understand what I'm saying. Basically, how to use if statement with only changes to the preference screen code.

Thank you!

Yuvan raj
Regular
Posts: 32
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Re: Toggle Quick menu Text to Quick menu ICONS

#5 Post by Yuvan raj » Mon Feb 22, 2021 5:32 am

zmook wrote:
Sun Feb 21, 2021 4:21 pm
1. Somewhere in your options, add this:

Code: Select all

default persistent.quick_icons = True
2. In your preferences screen, add this:

Code: Select all

                    textbutton _("Use Icons") action ToggleVariable("persistent.quick_icons")
3. in the quick_menu `if`, use `if persistent.quick_icons:`
Thank you so much for the clear explanation. i made it work! Again Thank you.
I have one doubt though. This is my preference screen code
Image
And this is my
Image
I have to use 'if not' which I think means, by default the persistent. quick_icon is False and when I click it it becomes true. And since it is true textbutton is I use only 'if' then textbutton is displayed. I can use 'if not' or just swap the textbutton and imagebutton lines. But how to change it so that by default the persistent.quick_icon is True and when I click the button it becomes False and so if I use if then it won't be displayed?
I hope you understand what I'm saying. Basically, how to use if statement with only changes to the preference screen code.

Thank you!

cheonbyeol
Regular
Posts: 37
Joined: Thu Feb 04, 2021 9:04 am
Contact:

Re: Toggle Quick menu Text to Quick menu ICONS

#6 Post by cheonbyeol » Mon Feb 22, 2021 9:04 am

As zmook wrote, you declare the default value to be true:

Code: Select all

default persistent.quick_icons = True
Put this line at the beginning of one of the .rpy files.
The rest will work the same.
Note: default is for when the game is first opened, afterwards it will just remember how the player left it. So you won't see an immediate change in behavior when you testrun it (unless you clear persistent data).

Yuvan raj
Regular
Posts: 32
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Re: Toggle Quick menu Text to Quick menu ICONS

#7 Post by Yuvan raj » Mon Feb 22, 2021 10:25 am

cheonbyeol wrote:
Mon Feb 22, 2021 9:04 am
As zmook wrote, you declare the default value to be true:

Code: Select all

default persistent.quick_icons = True
Put this line at the beginning of one of the .rpy files.
The rest will work the same.
Note: default is for when the game is first opened, afterwards it will just remember how the player left it. So you won't see an immediate change in behavior when you testrun it (unless you clear persistent data).
Thank you. It worked! Now I have one doubt. The code works but this is for learning.
This is my quick menu screen code.
Image
And this is my preference screen code.
Image
I'm using 'if not' statement. How can I use 'if' statement without swapping the textbuttons and imagebuttons and only changing the preference screen code?
(When I click the 'use icon', it should make it false and the if statement would make this code like 'if false use textbutton,else imagebutton)
I hope you understand what I'm asking.
Thank you!

cheonbyeol
Regular
Posts: 37
Joined: Thu Feb 04, 2021 9:04 am
Contact:

Re: Toggle Quick menu Text to Quick menu ICONS

#8 Post by cheonbyeol » Mon Feb 22, 2021 10:46 am

There's several ways you can do a "straight if" rather than an "if not", without changing any of the behavior.

Option 1:
(personally think this is the most straightforward)
Leave preferences as is, and reverse the quick menu code:

Code: Select all

if persistent.quick_icons:
    imagebutton ...
    ...
else:
    textbutton ...
    ...
Option 2:
This is a bit of backwards logic...
In this case, I would rename the variable to persistent.quick_textbuttons to avoid confusion.
In the preferences, you can do textbutton _("Quickmenu icons") action InvertSelected(ToggleVariable("persistent.quick_textbuttons"))
And in quick menu code

Code: Select all

if persistent.quick_textbuttons:
    textbutton ...
    ...
else:
    imagebutton ...
    ...

Yuvan raj
Regular
Posts: 32
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Re: Toggle Quick menu Text to Quick menu ICONS

#9 Post by Yuvan raj » Mon Feb 22, 2021 2:11 pm

cheonbyeol wrote:
Mon Feb 22, 2021 10:46 am
There's several ways you can do a "straight if" rather than an "if not", without changing any of the behavior.

Option 1:
(personally think this is the most straightforward)
Leave preferences as is, and reverse the quick menu code:

Code: Select all

if persistent.quick_icons:
    imagebutton ...
    ...
else:
    textbutton ...
    ...
Option 2:
This is a bit of backwards logic...
In this case, I would rename the variable to persistent.quick_textbuttons to avoid confusion.
In the preferences, you can do textbutton _("Quickmenu icons") action InvertSelected(ToggleVariable("persistent.quick_textbuttons"))
And in quick menu code

Code: Select all

if persistent.quick_textbuttons:
    textbutton ...
    ...
else:
    imagebutton ...
    ...
Thank you so much. This invert selection is what I was asking for. Just wanted to know the concept behind the code like whether when you switch on the 'toggle', its value become 'true' whether it was false before or true.

Post Reply

Who is online

Users browsing this forum: No registered users