Called Module 可调用模组
从稳定状态中调用的模组称为“Called Module可调用模组”,调用形式为ModuleName(param1, param2),在模组名后必须有一组小括号。<br /> "可调用模组"中,还可以调用别的模组,但是注意不要形成循环调用和递归调用。<br /> 通过引用传递参数。<br /> Return语句是可选的。
经观察,Return不会阻止程序的运行,如下代码Return后的 ZText 和 IF 不会被阻断。
{================================= System ====================================}
{=============================================================================}
(
System { Provides access to system library functions };
Layer { Provides access to the application layer };
)
[
Graphics Module { Contains user graphics };
Counter Module { Another module };
WinTitle = "User Application" { Window title };
RunningOnVIC { TRUE if this is a VIC session };
]
Init [
If 1 Main;
[
RunningOnVIC = IsVICSession();
]
]
Main [
Window( 0, 0 { Upper left corner },
800, 600 { View area },
800, 600 { Virtual area },
Graphics() { Start user graphics },
{65432109876543210}
0b00010000000110011,
Concat(WinTitle, RunningOnVIC ? " - %S" : ""),
7, 1);
]
<
{============================= System\Graphics ===============================}
{ This module handles all of the graphics for the application }
{=============================================================================}
Graphics
[
X = 1;
Y = 1;
]
Main [
ZText(100,100,Concat("X = ",X),2,0);
ZText(100,200,Concat("Y = ",Y),2,0);
Counter(X);
Y = Counter(X);
]
{ End of System\Graphics }
>
<
{============================= System\Counter ================================}
{ A simple called module to increment and display a value }
{=============================================================================}
Counter
(
LocalVar = 0;
)
Main [
Return(LocalVar * 2);
ZText(100,140,Concat("LocalVar = ",LocalVar),2,0);
IF TimeOut(1,5);
[
LocalVar++;
]
]
>
多次调用模组
多次调用模组,感觉是创建了多个模组实例,这些实例在同时运行,就像高级语言中的多线程一样。
例1,显示窗口中,X的值以1为步距进行增加。
{================================= System ====================================}
{=============================================================================}
(
System { Provides access to system library functions };
Layer { Provides access to the application layer };
)
[
Graphics Module { Contains user graphics };
Counter Module { Another module };
WinTitle = "User Application" { Window title };
RunningOnVIC { TRUE if this is a VIC session };
]
Init [
If 1 Main;
[
RunningOnVIC = IsVICSession();
]
]
Main [
Window( 0, 0 { Upper left corner },
800, 600 { View area },
800, 600 { Virtual area },
Graphics() { Start user graphics },
{65432109876543210}
0b00010000000110011,
Concat(WinTitle, RunningOnVIC ? " - %S" : ""),
7, 1);
]
<
{============================= System\Graphics ===============================}
{ This module handles all of the graphics for the application }
{=============================================================================}
Graphics
[
X = 1;
Y = 1;
]
Main [
ZText(100,100,Concat("X = ",X),2,0);
ZText(100,300,Concat("Y = ",Y),2,0);
Y = Counter(X);
]
{ End of System\Graphics }
>
<
{============================= System\Counter ================================}
{ A simple called module to increment and display a value }
{=============================================================================}
Counter
(
LocalVar = 0;
)
Main [
ZText(100,140,Concat("LocalVar = ",LocalVar),2,0);
IF TimeOut(1,2);
[
LocalVar++;
]
Return(LocalVar * 2);
]
>
例2,在 Y = Counter(X); 前增加一行Counter(X); ,如行45行46。则显示窗口中,X的值会以2为步距进行增加。
{================================= System ====================================}
{=============================================================================}
(
System { Provides access to system library functions };
Layer { Provides access to the application layer };
)
[
Graphics Module { Contains user graphics };
Counter Module { Another module };
WinTitle = "User Application" { Window title };
RunningOnVIC { TRUE if this is a VIC session };
]
Init [
If 1 Main;
[
RunningOnVIC = IsVICSession();
]
]
Main [
Window( 0, 0 { Upper left corner },
800, 600 { View area },
800, 600 { Virtual area },
Graphics() { Start user graphics },
{65432109876543210}
0b00010000000110011,
Concat(WinTitle, RunningOnVIC ? " - %S" : ""),
7, 1);
]
<
{============================= System\Graphics ===============================}
{ This module handles all of the graphics for the application }
{=============================================================================}
Graphics
[
X = 1;
Y = 1;
]
Main [
ZText(100,100,Concat("X = ",X),2,0);
ZText(100,300,Concat("Y = ",Y),2,0);
Counter(X);
Y = Counter(X);
]
{ End of System\Graphics }
>
<
{============================= System\Counter ================================}
{ A simple called module to increment and display a value }
{=============================================================================}
Counter
(
LocalVar = 0;
)
Main [
ZText(100,140,Concat("LocalVar = ",LocalVar),2,0);
IF TimeOut(1,2);
[
LocalVar++;
]
Return(LocalVar * 2);
]
>
Launched Module 可加载模组
从脚本块中调用的模组,或者通过Launch函数调用的模组,称为“Launched Module 可加载模组”。<br /> 通过传值的方式传递参数。<br /> 当父模组停止时,或一个Slay语句执行时,这个“可加载模组”就会停止。<br /> “可加载模组”中不能有Return语句,如果有的话,将被认为是subroutines子程序。
Subroutine Module 子程序模组
“子程序模组”也是从脚本块中被调用。它有一个或多个Return语句。
脚本块调用“子程序模组”后将暂停,等到“子程序模组”返回后,再继续向下执行。
如果从稳定状态中调用“子程序模组”,稳定状态不会暂停。