Please, I’m looking for some help/tips on breaking an applet into multiple scripts/libraries.
I just encountered the errOSAInternalTableOverflow error with one of my applets. Mark has helpfully explained, as I suspected, that I have too many lines of code in the applet and need to break it up.
This is actually v 2.0 of this project. The earlier version was broken up into different scripts but I decided to rewrite it all as one script because of issues that were arising from having it split up, such as problems with displaying progress indicators and tracking bugs. Admittedly the way I was doing it was pretty messy – I was using the load script command rather than the use script statement – and the use script statement appears to solve many of those issues.
The things I’m still concerned about are:
- library handlers calling handlers from other libraries or from the main script; and
- sharing global variables/properties.
Library handlers calling handlers from other libraries or from the main script
By way of explanation, it seems I’ll need to use more than one script library to avoid errOSAInternalTableOverflow.
So let’s say I create two scrips “lib1.scpt” and “lib2.scpt” both inside the “Script Libraries” folder inside my applet’s Resources folder. This applet is being distributed among work colleagues so ideally everything (including any libraries) will be contained in the one bundle.
Can lib1 contain handlers that call handlers from lib2 or vice-verser? If so, how is it done? I just tried to test it by including a use script “lib2” statement in lib1 but it got an error couldn’t find script “lib2”.
Sharing global variables/properties
The applet is designed to be used by multiple users on different machines all sharing the same pool of data. The data is saved in a shared folder. I’ve been comparing different ways to store the data – it’s currently written and read to disk using AS’s read/write commands with a somewhat convoluted way of ensuring there are no sync conflicts. All the other handlers in the applet basically do stuff with that shared data and, if they want to save changes to the data, they call another handler that writes the data to disk in a way that avoids sync conflicts.
One of the ways I avoid sync conflicts is that whenever a handler is going to do something significant, it calls a refreshData() handler that reads the shared data and, if it has been modified, updates the myriad global variables that represent that data. Obviously there’s a fair bit of optimisation that goes into this – too frequently and things run too slow, too seldom and things risk getting out of sync.
Currently thanks to global variables and all the code being contained in one script the process of updating/refreshing the data is pretty simple. But seems like all that will change after splitting it into different scripts.
From my very limited reading/testing it seems like the only way to do it is to:
- declare the global variables as properties in each script; and
- expressly set the value of the variable for each script/library whenever it is changed (e.g. set lib1’s x to x, set lib2’s x to x).
In particular this second part seems like it’s going to be a nightmare especially if I need more than one library.
Does anyone please have any tips or recommendations for dealing with this?