Creating a graphics toggle without using if/else?
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.
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.
- astrokeofmadness
- Regular
- Posts: 160
- Joined: Sun Sep 28, 2014 1:46 am
- Completed: AAA:Book 1
- Projects: A Stroke of Apprehension
- Location: British Columbia, Canada
- Contact:
Creating a graphics toggle without using if/else?
I'd like to make a toggle option that enables or disables animations for my sprites, primarily for people with weaker computers. I am using the auto voice function, where I use the spreadsheet to get the name and name the voice files through it.
My original attempt at this was simply tossing a "Do you want animated sprites?"Yes/no menu at the start of the game. This led to a problem in which I had to use a setup like so:
if animationflag= yes
show animationsprite
Sally "Hello, what's up?"
else
show nonanimatedsprite
Sally "Hello, what's up?"
This has an issue in which both of Sally's lines are identical, but they will use a different voice file. This means to use this method I need to double the voice files, which is wasted filespace. I do not want to do this for that exact reason. The only alternative at the moment is to manually input the voice files for all of the Else spots... Which isnt ideal.
Is there any way to get this to work?(PS- if anyone knows how to add the toggle into the prefs screen let me know too cuz that would obviously be much better an option.)
My original attempt at this was simply tossing a "Do you want animated sprites?"Yes/no menu at the start of the game. This led to a problem in which I had to use a setup like so:
if animationflag= yes
show animationsprite
Sally "Hello, what's up?"
else
show nonanimatedsprite
Sally "Hello, what's up?"
This has an issue in which both of Sally's lines are identical, but they will use a different voice file. This means to use this method I need to double the voice files, which is wasted filespace. I do not want to do this for that exact reason. The only alternative at the moment is to manually input the voice files for all of the Else spots... Which isnt ideal.
Is there any way to get this to work?(PS- if anyone knows how to add the toggle into the prefs screen let me know too cuz that would obviously be much better an option.)
Re: Creating a graphics toggle without using if/else?
I'm not sure how the voice stuff is working, but couldn't you just do it like this?:
That should show the sprite you picked, and then, whichever sprite is showing, run the dialog once. I know it might not solve all your problems, but it should at least solve that one example.
Code: Select all
if animationflag= yes:
show animationsprite
else:
show nonanimatedsprite
Sally "Hello, what's up?"
- SundownKid
- Lemma-Class Veteran
- Posts: 2299
- Joined: Mon Feb 06, 2012 9:50 pm
- Completed: Icebound, Selenon Rising Ep. 1-2
- Projects: Selenon Rising Ep. 3-4
- Organization: Fastermind Games
- Deviantart: sundownkid
- Location: NYC
- Contact:
Re: Creating a graphics toggle without using if/else?
That wouldn't be the correct way to do it. You have to do it in the image itself rather than when you SHOW the image ingame. You do this by using ConditionSwitch.
Just as an example I have a variable "daytime" that controls whether the sprites show nighttime versions (tinted darker). This is the code for the sprite:
In your case it would be a persistent variable set from the preferences screen with a button like so:
Just as an example I have a variable "daytime" that controls whether the sprites show nighttime versions (tinted darker). This is the code for the sprite:
Code: Select all
image side dougal = ConditionSwitch(
"daytime == True", "image/chars/dougal/normal.png",
"daytime == False", ImageReference ("dougal night"),
)
image dougal night = im.MatrixColor("image/chars/dougal/normal.png",
im.matrix.saturation(0.5)*im.matrix.tint(.66,.66,.93)*im.matrix.brightness(-0.05))Code: Select all
textbutton _("On") action SetField(persistent, 'animation_on', True)
textbutton _("Off") action SetField(persistent, 'animation_on', False)Re: Creating a graphics toggle without using if/else?
Hey Sundown, is it possible to get an im.Matrix thing like that to work with a complex LiveComposite image? I tried to enter the image name but it won't accept it, presumably because it only takes image file names?
- astrokeofmadness
- Regular
- Posts: 160
- Joined: Sun Sep 28, 2014 1:46 am
- Completed: AAA:Book 1
- Projects: A Stroke of Apprehension
- Location: British Columbia, Canada
- Contact:
Re: Creating a graphics toggle without using if/else?
Thanks Sundown, I'm gonna try to see if i can understand that enough to reverse engineer use it for my own project in the future.
Edit- got the first step to work, so super thanks, that's soo much better and will fix my issue of having to include a no animation patch now lol.
Okay I got the prefs button to work too, but with 1 problem, not sure if its a required problem that simply is a byproduct of the method or not. The value change in prefs only takes place on the start of a game and can't be changed afterterwords with the method I'm using to get this to work, which was a work around cuz what you gave me didn't seem to work. I got a animation_on is not defined error.
Code I'm using:
image mollyanimation1 = ConditionSwitch(
"animations == True", ImageReference ("mollyanimation"),
"animations == False", "mollybase.png",
)
label start:
if persistent.animations is False:
$ animations = False
if persistent.animations is True:
$ animations = True
In Screens:
frame:
style_group "pref"
has vbox
label _("Animations")
textbutton _("Enabled") action SetField(persistent, 'animations', True)
textbutton _("Disabled") action SetField(persistent, 'animations', False)
Obviously the issue is me using the $ animation flag, but it kept requesting I define the value and thats the only way I know how.
Edit- got the first step to work, so super thanks, that's soo much better and will fix my issue of having to include a no animation patch now lol.
Okay I got the prefs button to work too, but with 1 problem, not sure if its a required problem that simply is a byproduct of the method or not. The value change in prefs only takes place on the start of a game and can't be changed afterterwords with the method I'm using to get this to work, which was a work around cuz what you gave me didn't seem to work. I got a animation_on is not defined error.
Code I'm using:
image mollyanimation1 = ConditionSwitch(
"animations == True", ImageReference ("mollyanimation"),
"animations == False", "mollybase.png",
)
label start:
if persistent.animations is False:
$ animations = False
if persistent.animations is True:
$ animations = True
In Screens:
frame:
style_group "pref"
has vbox
label _("Animations")
textbutton _("Enabled") action SetField(persistent, 'animations', True)
textbutton _("Disabled") action SetField(persistent, 'animations', False)
Obviously the issue is me using the $ animation flag, but it kept requesting I define the value and thats the only way I know how.
Re: Creating a graphics toggle without using if/else?
One tip for the forums, surround your coding with [ code ] . . . [/ code ] (without the spaces), this leaves all the indentation in, and is helpful for figuring out where indent errors might be occurring.
Another tip, instead of saying "if X == True" or "if X == False" you can just use "if X" and "if not X". They work the same either way. "if X" will be considered "true" so long as X is anything other than 0, while "if not X" is considered true only when X is 0 or False (I personally set binary options to 1 or 0 instead of True or False, but it apparently makes no difference).
A couple of troubleshooting tips, one, try using the shift-d command in the game to bring up the developer's toolkit, and open the variable viewer. See if the variable you wanted to change has been properly changed. Second, when you write the code, put in testing flags to keep track of what you're working with, so for example, put a "[animations]" (with the quotation marks) before your if statement, and then put another after it, to see whether the variable is updating.
Specific to this though, I think the problem is that it only checks your if statements once, when the game launches, and then never again. So it will never do anything after the game has started. If you want it to keep checking that statement, you need to put it someplace else, probably in the screen itself.
Another tip, instead of saying "if X == True" or "if X == False" you can just use "if X" and "if not X". They work the same either way. "if X" will be considered "true" so long as X is anything other than 0, while "if not X" is considered true only when X is 0 or False (I personally set binary options to 1 or 0 instead of True or False, but it apparently makes no difference).
A couple of troubleshooting tips, one, try using the shift-d command in the game to bring up the developer's toolkit, and open the variable viewer. See if the variable you wanted to change has been properly changed. Second, when you write the code, put in testing flags to keep track of what you're working with, so for example, put a "[animations]" (with the quotation marks) before your if statement, and then put another after it, to see whether the variable is updating.
Specific to this though, I think the problem is that it only checks your if statements once, when the game launches, and then never again. So it will never do anything after the game has started. If you want it to keep checking that statement, you need to put it someplace else, probably in the screen itself.
Last edited by Onishion on Wed Aug 12, 2015 2:40 pm, edited 1 time in total.
Re: Creating a graphics toggle without using if/else?
Minor nit: None also evaluates to false using that syntax.Onishion wrote:One tip for the forums, surround your coding with [ code ] . . . [/ code ] (without the spaces), this leaves all the indentation in, and is helpful for figuring out where indent errors might be occurring.
Another tip, instead of saying "if X == True" or "if X == False" you can just use "if X" and "if not X". They work the same either way. "if X" will be considered "true" so long as X is anything other than 0, while "if not X" is considered true only when X is 0 or False (I personally set binary options to 1 or 0 instead of True or False, but it apparently makes no difference).
A couple of troubleshooting tips, one, try using the shift-d command in the game to bring up the developer's toolkit, and open the variable viewer. See if the variable you wanted to change has been properly changed. Second, when you write the code, put in testing flags to keep track of what you're working with, so for example, put a "[animations ]" (with the quotation marks) before your if statement, and then put another after it, to see whether the variable is updating.
Specific to this though, I think the problem is that it only checks your if statements once, when the game launches, and then never again. So it will never do anything after the game has started. If you want it to keep checking that statement, you need to put it someplace else, probably in the screen itself.
For the OP, why not check persistent.animations directly in the ConditionSwitch?
- astrokeofmadness
- Regular
- Posts: 160
- Joined: Sun Sep 28, 2014 1:46 am
- Completed: AAA:Book 1
- Projects: A Stroke of Apprehension
- Location: British Columbia, Canada
- Contact:
Re: Creating a graphics toggle without using if/else?
Whoa Philat, you fixed it! Your a genius! It's funny, I plugged persistent.animations into everything but that... Anyways, seems to be working completely now, thanks much everyone.
Who is online
Users browsing this forum: Bing [Bot], Ocelot

