All statements end with a semicolon. the point is used only once times per unit to mark the end. We can write several instructions on the same line. An instruction block is delimited by the « (» and «) »instructions.
|VAR||Used for creating variables|
|ExternalFunctionParameters||System variable containing the parameter value of a function.|
|SessionEntryCode||System variable containing the value as a parameter of a function.|
|ExternalFunctionParametersWebPost||This variable will contain the send parameters by POST has a script on FM|
|GotoUssdCode||Redirects the user to a terminal address provided.|
|EXIT||Stop the execution of instructions in a script|
|AND / OR||Logical test between two expressions|
|FOR…… DO / WHILE…. DO||Reserved for loops|
|IF / ELSE||Conditional test|
|USER_Connection_GUI||Defines the active terminal initialized in a user.
0 : Native Terminal (USSD).
1 : Graphic Terminal (web, Android, Ios)
Here are some tips to make the code more readable:
Comments are annotations made by the developer to explain the functioning of a script, an instruction or even a group of instructions. comments do not hinder the execution of a script.
There are two types of comments: comment on a line and multiline comments.
// Comment on one line /* Comments on several lines */
Note: No compilation directive is implemented yet on comments Fmscript at the time this documentation is written (02/2019). the text put in comment will be just considered a raw element ignored during compilation.
The declaration of a variable is made in a particular clause of the program, identified by the key word VAR. The constraints of formation of an identifier are: only the first 63 characters are taken into account, accented characters are forbidden, the difference is lower / upper case not taken into account, it must start with a letter or underline. It is possible to declare several variables of the same type in one line, each being separated by a comma.
VAR Result : String ; VAR GotoUssdCode : String ; VAR Amount : Double ; VAR i,j : Integer ; // Redirect the user to his balance GotoUssdCode := '*fm*21#'; Result := 'Hello World' ; Exit ;
The dialog box ShowMessage()
ShowMessage() is a simple statement, called function, that displays a dialog box containing a message. This message is placed between single quotes, even placed between the parentheses of the function ShowMessage()
VAR Result: String ; ShowMessage('Hello World'); Exit;
Scope of a variable
At the script level, the variables are local to the script where they are declared and are stored in the stack segment. Sharing of data between scripts is done through sessions (we'll talk about it later).
Basic types are:
There are different system routines for the management of ordinal types:
|Pred||Returns the predecessor of the argument in the order determined by the type of given|
VAR Result: String ; VAR i,j,k: Integer ; //---- routine K := PRED(5); // K vaut 4 ShowMessage(' K = '+IntTOStr(K)) ; Exit ;
To assign a variable to another variable of another type it is necessary to use the cast (Casting). In FM script, it is possible to use a system type conversion routine:
|Round||Converts the value of a real type to that of an integer type, rounding its value|
|IntToStr||Converts a number to a string|
|StrToInt||Converts a string to a number, displaying an error if the string is incorrect|
|FloatTOStr||Convert a Float to a String|
|StrToFloat||Convert a String to a Float|
Fmscript integrates two other stunning cast functions: StrToArray and ArrayToStr. These take two instead of one parameter like the others.
StrToArray(ArrayName : String, StringName : String, Delimiter : String);
ArrayToStr(ArrayName : String, ADelimiter : String);
VAR Result : String ; VAR GotoUssdCode : String ; VAR Amount : Float ; VAR i,j : Integer ; // Redirect the user to his balance GotoUssdCode := '*fm*21#'; I := StrTOInt('25') ; ShowMessage(' I = '+IntTOStr(I)) ; Exit ;
VAR Result : String ; VAR GotoUssdCode : String ; VAR ValueStr : String ; VAR i,j : Integer ; // Redirect the user to his balance GotoUssdCode := '*fm*21#'; // Initial String ValueStr := 'FM Script is the Best'; // Convertion of our string into a table named ArrayName StrToArray('ArrayName', ValueStr, ' '); //--- the function uses to get an element of the array is //--- ArrayGetValue(ArrayName : String, APosition : Integer); Result := ArrayGetValue('ArrayName', 1); //- contient ‘Script’ Exit ;
Where to put the code in the page
So far, many are wondering how to start and run a FM script code. Before getting there I suggest that we discover some indispensable bases.