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.
How can I use functions that are inside screens? I tried understanding dragging when I wrote this, and the card_dragged function that is the drag callback works flawlessly, but when it wants to call the function snapcard, I get an error that it is not defined.
I know I can just put the functions outside, but I like my data tidy and grouped.
That's the beauty of the undefined behavior: anything can happen. Even that incorrect code will work.
While RenPy wants python functions to be defined during init phase, it does not take any additional steps to ensure that code that violates that principle won't work. Your callback simply didn't trip anything which requires that, while attempting to use other did (though I highly suspect that you actually run into scope issues there, which is another problem that arises from attempting to define something that is intended to be defined globally in local scope).
This is like running a red light or driving drunk: for many people it works and they did not run into any probles eve. Doesn't mean that it is a good idea to do so.
That's funny. I always imagined screens to behave like classes in that regard, so that I *can* define local functions that exist in the namespace of that screen only; and I'm sure I already used this to have small specialized functions there, probably small and straightforward enough (like a pythagorean calculation of distance) that it all worked.
So that's out the window Meh.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)