© 2012 MyEzApp Inc. (This page is made with Star Script)
Star Script Tutorial
Star Script is the language behind applications within the MyEZApp.com system. This simple programming language is designed to enable non-programmers to build powerful applications through intuitive, natural commands.
Star Script works by taking arbitrary input (i.e, "hello world") and extracting programming structure during compilation. Based on that programming structure, the script is executed and results are displayed. To make it easier to analyze a program written in Star Script, the editor displays the program in a tree structure
If you want to try out Star Script, just open a Star Script Editor. This editor is a playground for you to try out the language. It does not allow you to save files or access database. If you want to develop applications on myezapp.com, you should register for a myezapp.com account and use the File Manager. The myezapp.com File Manager is the IDE (integrated development environment) for the Star Script language.
To use the File Manager: - Click on the Files Icon from the System Tab on the main home screen. This will open the File Manager. - There are two ways to program in Star Script. - One way is to click on a .ws file from the file tree on the left-hand side of the File Manager. This will open the script in the Star Script Editor. - The other way is to click the "new button" and create a blank .ws file. This will allow you to start scripting from scratch.
Alternatively, you can download and install the Star Script compiler to run it in your local environment.
Star Script recognizes values such as number and text. Text needs to be enclosed in the double quote ("). If you want to use Star Script to calculate an expression. You can directly enter it. For example, if you enter
you will get
If you want to display the text 1 + 1 instead of getting it evaluated. You need to enclose it inside the quote, such as
you will get
Comments represent those elements within a script that are not part of the intended output but, instead, are meant to clarify other expressions, operations, or activities within the script. Star Script supports C-style comments. You can use // to skip a single line or /* */ to skip groups of lines.
Variables allow you to assign value to a placeholder. For example, in the following statement,
The variable "name" is assigned a value of the string "hello". Later on in your script where you make use of the variable "name", such as in the example below, the output will replace "name" with "hello".
The output of the script is
Variable names are not globally visible. They belong to scopes. For detailed explanation of scope and its rules, please refer to the next section.
Star Script supports several common primitive types. These include: - String (/lang/string.string) - Integer (int) - Floating Point Number (float) - Boolean (bool) - Character (char), and - Byte (byte)
Specifying a type of variable is optional. Based upon its use, Star Script will attempt to infer the kind of variable. So, for example
produces the same result as used in example before.
A variable has a value. The value of a variable can be changed using the assignment statement.
The assignment statement syntax is
Value expression can be in many forms, such as literal, expression, or function call. For example,
All Star Script names (variable names, function names and class/interface names) belong to a scope. Star Script has the below scopes: - Script Scope - Block Scope - Function Scope - Class Scope
Script scope defines the names that can be referenced within the script. Variable names defined outside any programming blocks are in the script scope. Any variable defined inside a tag, if statement, loop structure, function body, class, are not in the script scope.
Variables defined in the script scope are visible anywhere after the variable declaration, except the class declaration.
Block scope is the scope defined for a block of program. Below are the list of programming structures that are treated as blocks: - Tag - If statement - For loop - DoWhile loop
Variables defined in a block can only be referenced inside that block. They are not visible outside the block.
Function scope refers to the scope of a function body. Variables defined in a function body cannot be referred to outside of the function body.
Class scope refers to the scope of a class body. Variables defined in a class body can only be referred through the object reference syntax. For example, you can define a class person with a variable firstname. When you create an instance of the class person, for example
You can refer to the firstname of that person using
Without the object reference "per", you cannot directly refer to firstname outside of the class definition.
Loops are powerful logical constructs within programming. These enable you to create repeated actions that continue to happen so long as a given condition is met.
Star Script supports two types of loops: - For-loop, and - DoWhile loop
Below is an example of for-loop,
you will get
Each for-loop takes a loop variable. In the above example, the loop variable is "i". You can specify the starting number and ending number for the loop variable. At each step, the loop variable "i" will increase by one. Each for-loop ends with the keyword Next. If you want to increase the counter more than one at a time, you can optionally use the Step keyword.
you will get
A common structure in a web page is a table. Below is an example of how to generate a table,
you will get
| 1 * 2 = | 2 |
| 2 * 2 = | 4 |
| 3 * 2 = | 6 |
Another loop structure is DoWhile loop. Below is an example of a DoWhile loop:
you will get
The above DoWhile-loop is equivalent to the for-loop example referenced previously.
Condition statements (using "if" and "elseif") are powerful logic gates within any program. Star Script supports conditional statements enabling you to make more complicated programs.
you will get
If you have multiple branches, you can use the Elseif keyword. For example:
you will get
A function defines a re-usable block of code. It�s basically a container for activites within a program that you wish to call repeatedly. A function takes one or more parameters (variables that you send to the function when you wish to execute the code in it) and returns results. Functions can save a lot of time when programming as they allow you to utilize a block of code anywhere in your application without having to retype the block of code each time you want to use it. The following is an example function that calculate the sum from 1 to n.
In Star Script, you can use eiher a reference to call a function or a tag to call a function. Below is an example of using reference format,
The above example will output:
You can also call the function in tag format, for example:
will produce the same result as calling the function using "sum(10)". In Star Script, every function definition is a tag definition at the same time.
Functions are very powerful for creating more organized, reusable code.
Star Script is an object oriented programming language and therefore, supports classes. A class defines the blueprint of a type of objects. Below is an example of class person.
Running the code will produce the following output
Star Script recognizes tags similar to HTML and XML. This allows you to combine powerful scripting functionality with an extensible structure. A tag might be,
Star Script will attempt to match the tag to a class or function. If none are found, the tag will be printed to screen. If there is a match, the program will carry out the required activities. So using the example above, if there were a corresponding class, it might be written as such:
In order for a tag to have a relationship with a class, the class must "extend component" as well as include the "func process()" for rendering. Tags, though, can also reflect functions. For example,
When using this, the tag must include the variable that the function requires. So, to invoke this function within a tag, you would type:
Star Script has a built-in database you can use to store application data. To access the database, you need to use the Star Script database statements: Save, Load, Select, and Delete. Below is an example,
Running the code will produce the following output
For more information on the build-in database function, please refer to this Tutorial.
- Learning By Example: Creating First Page - Learning By Example: Using App Builder - Learning By Example: Using Component - Learning By Example: Request Processing - Learning By Example: Dynamic Configuration - Learning By Example: Database Access - Star Script Syntax Cheat Sheet - Star Script Blog