Xaeol
Xaeol

Reputation: 111

Kivy Reference Variables Across All Apps

This is a very basic question however, how could I store a variable to be referenced across all screens for a game? I was thinking of storing it as a property of 'App', is this a good idea/practice? How can I reference app from within one screen?

I.e

class Screen1(screen):
    def do_thing():
         #need to use var/func of app here
         app.do_different_thing

class Screen2(screen):
    pass

class MyGame(app):
    variable = ObjectProperty()
    def do_different_thing:
        #do stuff

How could I go about doing this (i.e what is the reference for MyGame within Screen1), is there any better way where Kivy programs are usually structured? I need to store a dictionary of object references to be used throughout the game if it's relevant.

Upvotes: 0

Views: 64

Answers (1)

inclement
inclement

Reputation: 29488

Putting app-global stuff in the app class is fine.

You can access the running app with App.get_running_app().

Upvotes: 2

Related Questions