Script Modules - Data Store
The data store is the other part of the model in the Script Module. The data store has a list of data files, in json, xml, csv, or any plain text format. They can be treated as files or as a hash table. Data can be added when developing the Script Module. It can also be added, removed, and edited dynamically during run time by the Script Module. They are saved in the PT options file for persistence because the user may not have write access to the pts file, and a way is needed to save the dynamic data. The data is also saved when a Script Module is edited and saved. Use the $putData(), $getData(), and $removeData() built-in functions.
$putData("helloData", "hello world"); var data = $getData("helloData"); $removeData("helloData"); |
Save Data in pka/pkt files
Dynamic data can also be added to pka/pkt files the same way as ExApps do. Register for the onSave event and in the callback function, put the save data.
ipc.ipcManager().registerEvent("onSave", null, onSaveCallback); ... onSaveCallback = function(src, args) { ipc.ipcManager().putSaveData(args.saveId, data); } |
When the pka/pkt file opens, PT will send the data to the Script Module if it has registered to the onOpen event.
ipc.ipcManager().registerEvent("onOpen", null, onOpenCallback); ... onOpenCallback= function(src, args) { doSomething(args.openData); } |
When the pka/pkt file opens, before sending the data to the Script Module, PT also checks if the Script Module has started. If not, it will start the Script Module if it is not set to disabled.