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.
-
eath
- Newbie
- Posts: 10
- Joined: Tue Jul 14, 2020 11:52 am
-
Contact:
#1
Post
by eath » Wed Jul 15, 2020 11:32 am
This should be a very simple thing, but I'm brand new to Ren'py and can't find it…
Here's what I want to do in pseudocode:
Code: Select all
show current imagebutton state (on or off)
imagebutton:
if x==True: imagebutton's image = "on.jpg"
if x==False: imagebutton's image = "off.jpg"
onclick: toggle x
replace/show current imagebutton state (on or off)
I feel like I'm ignorant of a very basic checkbox command that takes care of this in a simple way. I've spent hours looking up imagebuttons and my code just keeps getting more and more convoluted. Help! please!
If it matters, this will be a layer on top of another image.
Thanks!
Last edited by
eath on Mon Jul 20, 2020 6:50 pm, edited 1 time in total.
-
Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
-
Contact:
#2
Post
by Imperf3kt » Wed Jul 15, 2020 4:21 pm
You can use the selected_hover and selected_idle states for this
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
-
eath
- Newbie
- Posts: 10
- Joined: Tue Jul 14, 2020 11:52 am
-
Contact:
#3
Post
by eath » Wed Jul 15, 2020 8:48 pm
Well, this seems to do what I want it to do... but I am still willing to learn a better way of doing things!
Code: Select all
default buttonvalue = False
screen alternatebuttonswitch():
modal True
imagebutton:
focus_mask True
if buttonvalue == True:
idle "on.png"
else:
idle "off.png"
action [ToggleVariable("buttonvalue", True, False)]
show screen alternatebuttonswitch
If anyone can tell me how to add a quick "button shifted downwards" image during a tap, I'd be grateful!
-
Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
-
Contact:
#4
Post
by Imperf3kt » Wed Jul 15, 2020 9:18 pm
selected_idle and selected_hover do what you want.
You can use them like this.
Code: Select all
screen alternatebuttonswitch():
modal True
imagebutton:
focus_mask True
idle "off.png"
hover "off.png"
selected_idle "on.png"
selected_hover "on.png"
action NullAction()
More states and info here
https://www.renpy.org/doc/html/style_pr ... y-prefixes
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
-
eath
- Newbie
- Posts: 10
- Joined: Tue Jul 14, 2020 11:52 am
-
Contact:
#5
Post
by eath » Thu Jul 16, 2020 8:52 am
Thanks, all! That works great!
Users browsing this forum: Bing [Bot], span4ev