Hamster-Skripte: procedures

A procedure is a function without return value, and, therefore, can not be applied as an argument or parameter.

Quit (< exitcode >)

Quit

If a running script finishes and supplies if necessary an Exit-code back. Also with a normal script the order should be used quietly at the end.

Quit

Beep (< code >)

Beep

Spends system sounds. Meaningful values of the parameter <code> are in the module hamster.hsm with $SIGNAL_STOP, $SIGNAL_QUESTION, $SIGNAL_EXCLAMATION and $SIGNAL_ASTERISK vordefiniert.

$SIGNAL_STOP = 00000010 $;

$SIGNAL_QUESTION = 00000020 $;

$SICNAL_EXCLAMATION = 00000030 $;

$SIGNAL_ASTERISK = 00000040 $;

Beep

Error (< errmsg >)

Error

If a running script finishes and spends, besides, a (red) mistake message in the hamster's-protocol. Error ("file", $Filename, " not found! ")

Assert (< assertion >, < errmsg >)

Assert (< assertion >)

If a running script finishes and spends, besides, a mistake message if the mistake variable has been fulfilled. (Standard: " Assertion failed! ")

Assert (FileExists ($Filename), "file", $Filename, " not found! ")

Return (< retval >)

Return

If a Subroutine ("sub") finishes and sets the return value the Subroutine (standard: 0). Outside from Subroutienen the order "sub" the script finishes.

Return (42)

Return (uppercase ("end"))

Endsub

If the same effect has in principle like the procedure "return" - however, can set no explicit return value. As a return value of the Subroutine ("sub") it is automatically set 0.

Endsub

Var (< variable > [, <variable>...])

If variables within a script should be applied, these variables to the script must be announced before with 'var'. See also: "varset"

Var ($a, $b, $c)

Entercontext (< identifier >)

Leavecontext

Defines or finishes a program section in which variables are considered by the Interpreter as locally to a script section. The variables declared within the context are - also with Namensgleicheit with global variables - undependent on the global variables. The local context is valid to him with leavecontext is finished. These procedures may not be applied in Subroutinen, because these possess already automatically own local context.

Var ($a)

$a = 42

Entercontext ("test")

Var ($a)

$a = 999

Leavecontext

Print ($a) * the result is 42

Label (< identifier >)

If a jump brand declares for the "goto" procedure and "gosub" function. Is unnecessary normally, because enough structured instructions are available.

Label (niemals_bitte_goto_benutzen)

Goto (< identifier >)

Spunganweisung to a "label"

Goto (GOTOs_zu_benutzen_ist_fusch)

If (< condition >)

Else

Endif

If the condition is true, the program lines are implemented between "If" and "Else", otherwise the program lines between "Else" and "endif". Besides, of "Else-Zweig" is optional and can be left out therefore.

If ($Antwort = 42)

Print (" the answer is correct! ")

Else

Print (" the answer is wrong! ")

If ($welcheantwort = " the wrong answer ")

Print (" No answer! ")

Endif

Endif

Do

While (< condition >)

Repeat

Mark the beginning of a program ribbon. The program lines in "while" ribbon are implemented as long as, how <condition> a Worth True=Wahr zurückliefert.

* Sea(lake) examples under loop/endwhile/until and break / continue

Loop

Endwhile

Until (< condition >)

If the end of a program ribbon pretends. The program lines in the "Repeat" ribbon are implemented as long as, how <condition> a Worth True=Wahr zurückliefert.

Do

* Endless repetition...

Loop

While ($i < 10)

* And if raising will not forget, it can even end...

Endwhile

Repeat

* Ditto - demolition, as long as 10 is crossed...

Until ($i > 10)

While ($i < 10)

* Technically permissible, even if not very openly...

Until ($k=42)

For (< loop-var >, < limit1 >, < limit2 >, < step width >)

For (< loop-var >, < limit1 >, < limit2 >)

Makiert the beginning of a numerator's-ribbon. The ribbons variable is loaded while starting the program ribbon with <limit1>. Direction of travel and step width the Schleifenvarible is determined by the value <step width> and his(its) forerunner. The value <step width> fixes by which amount the ribbons variable is raised with every ribbons run or is decreased. Whether the value of the ribbons variable is raised with the ribbons run or is decreased, besides, depends on the forerunner of the <Step width> value. The ribbon is finished if the difference from <limit1> and <limit2> the neutral point happens with the ribbons run.

Var ($i, $k)

For ($i, 1, 10)

For ($k, 10, 1,-1)

Print ($i, " ", $k)

Endfor

Endfor

Endfor

If the end of a numerator's-ribbon "for" pretends.

* Sea(lake) example at for

Break (< condition >)

Break

If a program ribbon finishes. If a <condition> exists, the ribbon is only finished, if this expression True=Wahr zurückliefert. This order is Loop in Do / - ribbons the single clean possibility to leave the ribbon.

Do

Break (RasIsConnected)

* Do other things

Loop

Continue (< condition >)

Continue

If the program execution branches out to the beginning of a program ribbon. If a <condition> exists, it is only branched out, if this expression True=Wahr zurückliefert.

$i = 0

Repeat

Continue ($i = 42)

Inc ($i)

Until ($i > 100)

Sleep (< millisecs >)

If the program execution stops for the duration given(indicated) in Millisekunden.

Sleep (60000) * a minute

Trace (< onoff >)

If the announcement of the auszuführenden program lines switches on in the protocol or from.

<Onoff> 1 announcement in, <onoff> 0 announcements from.

Trace (1)

*.

Trace (0)

Dump

Indicates the contents of all variables.

Dump

Debug (< level >, < text > [, <text>...])

Debug (< level >)

Is given only <level>, this is set on the given value. If the text is given(indicated) in addition, the text is indicated just(exactly) when the current Level is more largely or immediately angebenen Level.

Debug (255)

Debug (10, " Now one sees it! ")

Debug (5)

Debug (10, " Now no more! ")

Runscript (< Scriptname > [, <parameters> [< wait >]])

Runscript (< Scriptname > [, <parameter>])

Runscript (< Scriptname >)

If the script <Scriptname> with the parameter <parameter> starts. If the variable <waits> with the Worth TRUE given(indicated), the appealing script waits for the end, the called script, otherwise the execution of the appealing Scriptes becomes directly vortgesetzt. (Multitasking) the called script can evaluate the handed over parameters with the functions paramstr and paramcount. Parameters can also contain quotation marks, while one them(her) doubles simply i.e. "hello" "Paulchen" "!" If becomes ' hello "Paulchen"! '.

Example:

Params.hsc

*! Hs2

Trace (0)

Var ($i1)

Print (" Params0-0: start ")

Print (" Params0-0: start params2.hsc / 1 ")

RunScript ("params2.hsc", "A" + chr (13) + "5000" + chr (13) + "15000", true)

Print (" Params0-0: Ends params2.hsc / 1 ")

Sleep (2000)

Print (" Params0-0: start params2.hsc / 2 ")

RunScript ("params2.hsc", "B" + chr (13) + "8000" + chr (13) + "5000", true)

Print (" Params0-0: Ends params2.hsc / 2 ")

Sleep (6000)

Print (" Params0-0: Done. ")

Quit

Params2.hsc

*! Hs2

* This script expects 3 parameters:

* 1) an ID (letter o.ä.)

* 2) duration in Millisekunden for the 1st break

* 3) duration in Millisekunden for the 2nd break

Var ($i1)

Print ("params2-" + ParamStr (1) + ": start... ")

Print ("params2-" + ParamStr (1) + ": sleep (" + ParamStr (2) + ")")

Sleep (ParamStr (2))

Print ("params2-" + ParamStr (1) + ": ParamCount = " + ParamCount)

For ($i1, 1, ParamCount+2)

Print ("params2-" + ParamStr (1) + ":" + $i1 + ": > " + ParamStr ($i1) + "<")

Endfor

Print ("params2-" + ParamStr (1) + ": sleep (" + ParamStr (3) + ")")

Sleep (ParamStr (3))

Print ("params2-" + ParamStr (1) + ": Done. ")

Quit (37)

Unable to open file