As chown33 as correctly stated, use a property at the top level of your script, and make sure it's declared outside of any handlers, including any explicit on run handler.
The way you write a property is shown below.
Code:
property propertyName : missing value -- A property with no or nil value.
property secondProperty : "Some text" as text -- A property with an intitial text value.
property thirdProperty : true as boolean -- A property with an initial boolean value.
property fourthProperty : 2.0 as real -- A property with an initial real value.
property lastProperty : 1 as integer -- A property with an intitial integer value.
--Other code and handlers written at this point.
In the above examples, the values will be retained between script executions, and can also be modified from anywhere in your script.
In the first property example, missing value is Applescript's version of nil or NULL, so you can also assign a value to it from anywhere within your script.
One word of caution, if your explicitly using scripting additions, you cant use the as boolean keywords as it will raise an error in OSX 10.9 Mavericks, like in the example below.
Code:
use scripting additions
property thirdProperty : true as boolean -- Will raise an ERROR so write like below.
property thirdProperty : true -- This is OK
It's a bug that has been reported to Apple.
Hope this helps.
Regards Mark