User manual - Scripting_Guide

NAURTECH SMART CLIENTS FOR WINDOWS CE AND POCKET PC
CETerm Scripting Guide Page 63
JavaScript engine in CETerm is not reset frequently like a browser JavaScript
engine, it is more likely that poor programming practices could exhaust memory.
5.8.2 Encapsulate Code in Functions
Whenever possible, put multiple script actions within a function. This should
minimize compilations and make it easier to use local variables as described
above. For example, the following actions could be in a script which is bound to
a key-combination:
CETerm.SetProperty( "session1.scanner.upca.enabled", true );
CETerm.SetProperty( "session1.scanner.msi.enabled", false );
CETerm.SetProperty( "session1.scanner.pdf417.enabled", false );
CETerm.PlayTone( 8, 2000, 200 );
CETerm.PlayTone( 8, 1500, 200 );
CETerm.PostIDA( "IDA_SCAN_APPLYCONFIG", 0 );
Or, the actions could be in a function which is loaded with “Load at Startup”
function enableUPCA()
{
CETerm.SetProperty( "session1.scanner.upca.enabled", true );
CETerm.SetProperty( "session1.scanner.msi.enabled", false );
CETerm.SetProperty( "session1.scanner.pdf417.enabled", false );
CETerm.PlayTone( 8, 2000, 200 );
CETerm.PlayTone( 8, 1500, 200 );
CETerm.PostIDA( "IDA_SCAN_APPLYCONFIG", 0 );
{
and the function call, in a separate script, could be bound to the key-
combination:
enableUPCA();
Using the later approach, the function is only compiled once, not each time the
key is pressed. In general, separating the function definitions from the invocation
is a good practice.
5.8.3 Limit Execution Time
Because the script engine acts like a “virtual user”, when a script is executing,
CETerm will seem unresponsive. You cannot have a script running continuously.
However, using events and timers, you can accomplish most tasks.