[SOLVED] SetVariable error

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
M0ti
Regular
Posts: 66
Joined: Mon Aug 15, 2011 1:06 pm
Contact:

[SOLVED] SetVariable error

#1 Post by M0ti » Sat Aug 20, 2016 2:58 am

Hi everyone,

right now I'm making small RPG for my best friend as a birthday gift.
In this game we have super powers and on start each battle we go through transformation like Sailor Moon.
But these transformations take some time so just like in anime I have made shorter versions and I want to make possible to change between them in preferences.

So I added to Preferences this:

Code: Select all

frame:
                style_group "pref"
                has vbox

                label _("Transformation lenght")
                textbutton _("Full") action SetVariable("persistent.short_trans", False)
                textbutton _("Short") action SetVariable("persistent.short_trans", True)
But this way it only returns error:

Code: Select all

While running game code:
File "renpy/common/00action_data.rpy", line 50, in get_selected
    return getattr(self.object, self.field) == self.value
AttributeError: 'StoreModule' object has no attribute 'persistent.short_trans'
Yesterday I have found out that this error happens because the variable persistent.sthort_trans wasn't declared beforehand but where to declar it? If I do it in init python -2548... whatever, it would change its value with every start of the program, right?
And if I put it in label start, this error will occurd if I go into the preferences before clicking on New game.
Last edited by M0ti on Sat Aug 20, 2016 8:20 am, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: SetVariable error: 'StoreModule' object has no attribute

#2 Post by Alex » Sat Aug 20, 2016 3:28 am

You need the SetField action here, like

Code: Select all

SetField(persistent, "short_trans", True)
https://www.renpy.org/doc/html/screen_a ... ta-actions

As for declaring this variable try

Code: Select all

init python:
    if not persistent.short_trans:
        persistent.short_trans = False

User avatar
M0ti
Regular
Posts: 66
Joined: Mon Aug 15, 2011 1:06 pm
Contact:

Re: SetVariable error: 'StoreModule' object has no attribute

#3 Post by M0ti » Sat Aug 20, 2016 8:15 am

And like by magic it's working now. Thank you very much.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]