|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Variable Definitions and Operations > MOD. - Modules > Modules |
MiniRobotLanguage (MRL)
MOD.Return
Leave the current Module and return to another Module
Intention
The MOD.Return command will leave the current module and return to another Module.
Unlike MOD.Leave it will NOT delete the variables and leave the Module and all its variables as they are.
The MOD.Return command can, for example, be used in sub-programs.
Then you can leave the sub-program with the MOD.Return command.
You leave the module and all the variables are kept. So they will exist when you enter the sub-program the next time.
The leave command also knows which module you have been in before, we call it the "last module", and will generally switch the to this last module where you have been before.
There is something important to this.
If you have switched to other modules inside this module, then the last module may not be the module where you have been coming from.
Therefore the leave command will just remember one last module where you have been before.
That is why the MOD.Leave command has a second option, if you want to actively decide to which module you want to leave out of this current module,
you can add a parameter to the leave command and then the MOD.Return|P1 command will exit the current module, and switch to the specified module P1.
In complicated constructs you can remember the last module where you have been in a variable inside your module and use it with the leave command to exit to the right module.
$$VAA=In Main
PRT.$$VAA
MOD.New|Left
MOD.New|Right
MOD.New|Other
GSB.Test
MOD.Enter|Main
MOD.Get Last Name|$$KEP
GSB.Test
GSB.LeftSub
DMP.gv
GSB.Test
GSB.Rightsub
DMP.gv
GSB.Test
DMP.gv
MBX.!
ENR.
'-----------------------------------------------------------
:LeftSub
MOD.Enter|Left
MOD.Get Last Name|$$KEP
PRT.Left KEP1 is: $$KEP
GSB.Test
' Here we leave to the Module which we came from.
PRT.Left KEP2 is: $$KEP
MOD.Return|$$KEP
RET.
'-----------------------------------------------------------
:Rightsub
MOD.Enter|Right
MOD.Get Last Name|$$KEP
PRT.Right KEP1 is: $$KEP
GSB.Test
' We remeber where we came from at the start here
' WE can now Switch Modes as we like
GSB.Othersub
PRT.Right KEP2 is: $$KEP
' Here we leave to the Module which we came from.
MOD.Return|$$KEP
RET.
'-----------------------------------------------------------
:Othersub
MOD.Enter|Other
MOD.Get Last Name|$$KEP
PRT.Other KEP1 is: $$KEP
GSB.Test
PRT.Other KEP2 is: $$KEP
MOD.Return|$$KEP
RET.
'-----------------------------------------------------------
:Test
MOD.Get Last Name|$$THI
PRT.We came from: $$THI
MOD.Get Name|$$CUR
PRT.We are here: $$CUR
RET.
'-----------------------------------------------------------
Syntax
MOD.Return[|P1]
Parameter Explanation
P1 - (optional) Is the name or number of a Module where to switch after Leaving the current Module, and deleting all Variables of the current Module.
If P1 is missing, means you do not give any parameter, then the MOD.Leave command will remember the last module where you have been before and switch to this module after leaving the current module.
Example
'***********************************
' MOD.Leave-Sample
'***********************************
$$VAA=In Main
PRT.$$VAA
MOD.New|Left Side Module
$$VAA=In Module 1
PRT.$$VAA
MOD.New|Right Side Module
$$VAA=In Module 2
PRT.$$VAA
' The following "MOD.Leave" will bring us back to Module 1 because we came from there
MOD.Return
PRT.$$VAA
MOD.Enter|Right Side Module
PRT.Is empty: $$VAA
DMP.gv
MBX.Done
ENR.
Remarks
-
Limitations:
-
See also:
•