Custom Preference in Screen Language [Solved]

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
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Custom Preference in Screen Language [Solved]

#1 Post 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 ...
Last edited by Aleema on Sun Jan 30, 2011 10:10 am, edited 1 time in total.

User avatar
jack_norton
Lemma-Class Veteran
Posts: 4096
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

Re: Custom Preference in Screen Language

#2 Post 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 :D
follow me on Image Image Image
computer games

User avatar
backansi
Veteran
Posts: 224
Joined: Sun May 31, 2009 7:15 am
Location: Korea, Republic of
Contact:

Re: Custom Preference in Screen Language

#3 Post 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. :|

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Custom Preference in Screen Language

#4 Post 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. >_<

User avatar
jack_norton
Lemma-Class Veteran
Posts: 4096
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

Re: Custom Preference in Screen Language

#5 Post by jack_norton »

That's the problem I had, I used a Class to set my variable (wasn't a persistent one though)
follow me on Image Image Image
computer games

User avatar
backansi
Veteran
Posts: 224
Joined: Sun May 31, 2009 7:15 am
Location: Korea, Republic of
Contact:

Re: Custom Preference in Screen Language

#6 Post 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:
        # ....

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Custom Preference in Screen Language

#7 Post by Aleema »

:D It worked!!
Thank you very much! You sure know your way around SL. :)

User avatar
octacon100
Regular
Posts: 163
Joined: Thu Sep 12, 2013 11:23 pm
Projects: Regeria Hope
Organization: Golden Game Barn
IRC Nick: Octacon100
Location: Boston, MA
Contact:

Re: Custom Preference in Screen Language [Solved]

#8 Post 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.
Image
Current Digital Projects -
Image
Regiera Hope Completed Game Forum Post

017Bluefield
Regular
Posts: 93
Joined: Mon Dec 30, 2013 1:55 am
Projects: Project Bluefield - Origins
Organization: Autumn Rain
Deviantart: playerzero17
itch: autumn-rain
Contact:

Re: Custom Preference in Screen Language [Solved]

#9 Post 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...

Post Reply

Who is online

Users browsing this forum: No registered users