Hamster-Scripts: Functions (built-in)

Global

GlobalValueSet( <name>, <value> )

Creates or changes a global value with the given <name>, that all running scripts can access and that persists while Hamster is running.
Note: Names starting with "system" are reserved for future use and can't be changed.

Returns: value.

GlobalValueSet( "State", "Transferring data" )
# transfer data
GlobalValueSet( "State", "" )

GlobalValueGet( <name>, <default> )

GlobalValueGet( <name> )

Returns the global value with the given <name>.
If no <default> is given and the global value does not exist yet, script is stopped with an appropriate error message. If <default> is given and the <name> does not exist yet, the value is created with the given <default>.

Returns: value.

print( "Current state: ", GlobalValueGet("State","") )

GlobalValueAdd( <name>, <number> )

Adds <number> to the global value with the given <name>.
If the value does not exist yet, it is automatically created with a value of 0.
Note: Names starting with "system" are reserved for future use and can't be changed.

Returns: new value (Integer)

GlobalValueAdd( "MyCounter", 1 )

GlobalValueAppend( <name>, <string> )

Appends <string> to the global value with the given <name>.
If the value does not exist yet, it is automatically created with an empty string.
Note: Names starting with "system" are reserved for future use and can't be changed.

Returns: new value (String)

GlobalValueAppend( "MyList", "listitem" + chr(13) + chr(10) )

GlobalValueWait( <name>, <waitvalue> )

Pauses the script until the global value with the given <name> becomes <waitvalue>.

Returns: true/false

GlobalValueWait( "State", "" )

GlobalEnter( <name> )

GlobalLeave( <name> )

Enters or leaves a section of scriptcode with the given <name>.
No other running script can enter a section with the same <name> at the same time. If another script already has entered such a section, the script will be paused until the section is left again by the other script.
Note: Names starting with "system" are reserved for future use and can't be used.

Returns: true/false.

GlobalEnter( "ExclusivePart" )
# (script code that may not run concurrently)
GlobalLeave( "ExclusivePart" )

GlobalOnce( <name>, <minutes>, <sub-name> )
...
GlobalOnce( <name> )

GlobalOnce returns <true> if the given <name> was not used for a given period, regardless which script called GlobalOnce with the same <name>.

Parameter <minutes> determines the period in minutes, after which GlobalOnce returns <true> again. If no <minutes> are given, a value of 1440 is used (= 24*60 minutes = 1 day).

If <sub-name> is given, this sub is started automatically after time has elapsed.

Returns: true if not used within given period, otherwise false.

var( $ItIsTimeToDoItAgain )
$ItIsTimeToDoItAgain = GlobalOnce( "MyHourly", 15 )
if( $ItIsTimeToDoItAgain )
   # once per 15 minutes
endif

do
   GlobalOnce( "Hourly", 60, HourlyTasks )
   GlobalOnce( "Daily",  24*60, DailyTasks )
   GlobalOnce( "Weekly", 7*24*60, WeeklyTasks )
   Sleep( 60000 )
loop

quit

sub HourlyTasks
   # ...
endsub

sub DailyTasks
   # ...
endsub

sub WeeklyTasks
   # ...
endsub

[www.elbiah.de Hamster Playground Documentation]