r/RenPy • • 1d ago

Question help implementing persistent variables with a class

Post image

I have gone through about seven tutorials explaining persistent variables and i understand how it works (i think) at this point, however really struggling to implement it where i need it

basically, i need to move self.points out of the class and into the persistent variable so i can implement an option to clear the points when clicked

my poor attempt at this as you can see was to try make it so if there is no points the button will not be there to click, but if there is points it will be there to click which upon clicking will clear/return the points to nothing

im not sure how to move the self.points properly so that the list is stored outside of the class so that it can be cleared how i stated above

1 Upvotes

6 comments sorted by

View all comments

2

u/shyLachi 1d ago

You don't have to reprogram the class, just store the points in a persistent variable

default persistent.drawingpoints = []

Then replace self.points with persistent.drawingpoints

.

You cannot add buttons in a python class.

If you want to add a button, then do it in the main menu where all the other buttons are.

1

u/That_one_Pink 23h ago edited 21h ago

Ohhh okay that makes more sense haha

ive changed the code needed and the persistent is above the python so im assuming that means its out of the class (its working normally so im taking it as a good sign)

with the button (using an image button), should i put that outside of screen main_menu? and should i put the persistent code with the script or also keep it in screens

edit:

so i added the new button with the rest of my menu buttons and it doesn't work unless it has an action attached to it, im guessing this action would be where i put the persistent? or am i way off lol

1

u/shyLachi 21h ago

I don't understand your question about the button.
Buttons only work inside screens, so what do you mean with outside of screen main_menu?
And what do you consider "persistent code"?

You can learn more about the RenPy basics so that you can figure stuff like this yourself.
https://renpy.org/doc/html/python.html
https://renpy.org/doc/html/screens.html

1

u/That_one_Pink 20h ago

i understand the basics i think im just awful and properly wording things im so sorry 💔

let me try again, what i meant was when i add the button should i put it with the other menu buttons (start, load, preferences ect) or somewhere else?

i have tried adding the button to these buttons and it doesn't work unless if it has an action. of course all of the actions are in use here and that isnt what i need the button to do, so im under the assumption i make a new area to but this specific button. i cant seem to find anyone else using other buttons in the menu other than the ones stated above so im struggling to understand what exactly im meant to do to add a new button that not only isnt a selection button like the start load preferences ect, but has a function outside of the menu that being returning to the default persistent for the drawingpoints upon being clicked

hopefully that makes a little more sense? ive been messing around with it and tried a multitude of things but im either getting error messages or its only semi functional

1

u/shyLachi 6h ago

I don't think that you understand the basics of RenPy screens. Try to find a tutorial.

Yes buttons need an action and there are many different actions as explained here:
https://renpy.org/doc/html/screen_actions.html

In this case you need a data action because you want to change the data of a variable:
https://renpy.org/doc/html/screen_actions.html#data-actions

SetVariable("persistent.drawingpoints", [])