Page 1 of 1
Custom Preference in Screen Language [Solved]
Posted: Sun Jan 30, 2011 8:35 am
by Aleema
Dumb question time.
The switch to SL seems like it would be perfect for adding whatever we want to game menus, since having a custom preference option wasn't possible with imagemap layouts before.
Thing is, I'm stupid, and I can't figure out how to add a custom preference option to the preferences screen that isn't hard coded in.
What actions should I implement for this to happen, so I could have an option to turn off mini-games, for example?
Is it possible? Because I'm looking at the guts of Ren'Py, and the "preferences constructor" looks pretty hard coded to not accept anything but what's there ...
Re: Custom Preference in Screen Language
Posted: Sun Jan 30, 2011 9:21 am
by jack_norton
I did that on PS to change layout and add the "difficulty" setting in the options, but it's no use posting the code here since is a total hack. I'd like to see (whenever pytom has time of course) some tutorials about doing this the "official way". Another option I wanted to use is "delete savegame" option in the load/save, but since I had fear of deleting users wrong files I gave up on this one
Re: Custom Preference in Screen Language
Posted: Sun Jan 30, 2011 9:32 am
by backansi
Aleema // Well, there's ToggleVariable or SetVariable action and I think you can simply add it to your preference screen.
Code: Select all
init:
screen preference:
#....
has vbox
text 'Do you want to do Mini-Games?'
hbox:
textbutton 'Yes' action SetVariable('minigame', True)
textbutton 'No' action SetVariable('minigame', False)
#...
label minigame:
if not minigame:
return
else:
# ....
Anyway I didn't test it so I'm not sure it would work with your minigame code.
Re: Custom Preference in Screen Language
Posted: Sun Jan 30, 2011 9:41 am
by Aleema
Oh, the variable has to be in quotes? I saw that action and tried it, got some string error, so I guess that was the original problem. Thanks, it worked.
Next problem: preferences should be persistent so you don't have to set them every time. I replaced a generic variable with this:
Code: Select all
textbutton _("Yes") action SetVariable('persistent.stopjukebox', True)
Got:
Code: Select all
AttributeError: 'module' object has no attribute 'persistent.stopjukebox'
Tell me I'm just being stupid again. >_<
Re: Custom Preference in Screen Language
Posted: Sun Jan 30, 2011 9:51 am
by jack_norton
That's the problem I had, I used a Class to set my variable (wasn't a persistent one though)
Re: Custom Preference in Screen Language
Posted: Sun Jan 30, 2011 10:05 am
by backansi
Ah... Try using SetFeild.
Code: Select all
init:
$ persistent.stopjukebox = '1'
screen test:
hbox:
textbutton "Yes" action SetField(persistent, 'stopjukebox', True)
textbutton "No" action SetField(persistent, 'stopjukebox', False)
textbutton "return" action Return()
label start:
call screen test
if persistent.stopjukebox:
#...
else:
# ....
Re: Custom Preference in Screen Language
Posted: Sun Jan 30, 2011 10:09 am
by Aleema
It worked!!
Thank you very much! You sure know your way around SL.
Re: Custom Preference in Screen Language [Solved]
Posted: Wed Feb 04, 2015 9:27 pm
by octacon100
I know I'm necro'ing the heck out of this topic, but it's extremely useful for anyone wanting to add their own preferences. I'd volunteer to write a page about this in the Ren'py online documentation from this post if people wanted it.
Re: Custom Preference in Screen Language [Solved]
Posted: Mon Oct 08, 2018 1:18 am
by 017Bluefield
octacon100 wrote: ↑Wed Feb 04, 2015 9:27 pm
I know I'm necro'ing the heck out of this topic, but it's extremely useful for anyone wanting to add their own preferences. I'd volunteer to write a page about this in the Ren'py online documentation from this post if people wanted it.
I'd really appreciate it...