Creating a graphics toggle without using if/else?

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
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?

#1 Post by astrokeofmadness » Tue Aug 11, 2015 1:38 am

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.)

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Creating a graphics toggle without using if/else?

#2 Post by Onishion » Tue Aug 11, 2015 2:43 am

I'm not sure how the voice stuff is working, but couldn't you just do it like this?:

Code: Select all

if animationflag= yes:  
    show animationsprite
else:
    show nonanimatedsprite
Sally "Hello, what's up?"
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.

User avatar
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?

#3 Post by SundownKid » Tue Aug 11, 2015 3:01 am

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:

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))
In your case it would be a persistent variable set from the preferences screen with a button like so:

Code: Select all

textbutton _("On") action SetField(persistent, 'animation_on', True)
textbutton _("Off") action SetField(persistent, 'animation_on', False)

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Creating a graphics toggle without using if/else?

#4 Post by Onishion » Tue Aug 11, 2015 4:07 pm

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?

User avatar
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?

#5 Post by astrokeofmadness » Wed Aug 12, 2015 4:30 am

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.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Creating a graphics toggle without using if/else?

#6 Post by Onishion » Wed Aug 12, 2015 1:53 pm

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.
Last edited by Onishion on Wed Aug 12, 2015 2:40 pm, edited 1 time in total.

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Creating a graphics toggle without using if/else?

#7 Post by philat » Wed Aug 12, 2015 2:05 pm

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.
Minor nit: None also evaluates to false using that syntax.

For the OP, why not check persistent.animations directly in the ConditionSwitch?

User avatar
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?

#8 Post by astrokeofmadness » Wed Aug 12, 2015 5:45 pm

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Ocelot