Access to objects/variables from previous run? - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: Access to objects/variables from previous run? (/showthread.php?tid=226956) |
Access to objects/variables from previous run? - SportySpice - 2015-05-14 Ok so the way Kodi works is that it runs my script for the first time. I then list a bunch of things using xbmcplugin.addDirectoryItem and give each a different URL, so the next time Kodi runs my script I know exactly which item was selected. So far so good, my question is this: After the user selects one of the list items, and Kodi runs my script again, can I somehow access any of the objects/variables I created in the previous run? (yes I am aware i can save them as files and load them up again but that's hardly efficient nor convenient) RE: Access to objects/variables from previous run? - learningit - 2015-05-15 One way in a plugin is to create "hidden" values/variables in settings.xml and use xbmcgui.setSetting() and xbmcgui.getSetting() to store/retrieve values. in settings.xml <settings> <setting id="var_1" type="text" visible="False" default=""/> </settings> in your plugin: xbmcplugin.setSetting(int(sys.argv[1]), id='var_1', value='a new value') v1 = xbmcplugin.getSetting(int(sys.argv[1]), 'var_1') RE: Access to objects/variables from previous run? - SportySpice - 2015-05-15 Do note that I wrote I'm aware I can save them to files, one way or the other. Also I need to load entire objects(aka class instances), and even lists of objects, so serialization will be needed. I doubt I can store all that data in settings.xml But still, I find it a bit unreasonable I even have to go through all this trouble. It seems extremely weird that when adding a ListItem you can only supply URLs and not simply a callback function that will run once the user clicks the item RE: Access to objects/variables from previous run? - learningit - 2015-05-15 A plugin just manages the event and has no context from previous runs. There is nothing to callback to. You can write a script, rather than a plugin, to manage events, etc that will remain resident. The only rough equivalent to a callback in a plugin is a listitem url can call a plugin with parameters. |