YOUSRC logo    YouTube logo  Twitter logo 
Login/Email: 
Password: 
or Register here | Cookie policy
  Rachel's Rabbit for younger codersELC for older coders
Step by step learning guide

Tutorial topics

Tutorial home

ELC language reference

Commenting your code

ELC app structure

An empty ELC program

Hello world

Functions

Defining variables

Function parameters

Using variables

Function return values

IF decisions

WHILE loops

FOR loops


Arrays of variables

Library functions

Game Tech - Depth & 3D

Game Tech - Shooting bullets

Dev Tech - How to debug

ELC language reference

Index
CONSTANT
FOR
FUNCTION
GLOBAL
IF
LET
LOCAL
RETURN
WHILE

Arrays
Comments
Function calls
TRUE and FALSE
GLOSSARY


See the glossary below for definitions of terms such as nvariable, wvariable$, etc



CONSTANT
Define a constant value to contant name that will not change as the code runs. The value can be a number (eg CONSTANT Count = 5), some words enclosed in quote marks (eg CONSTANT Result$ = "All okay"), or the enumerated boolean numbers TRUE or FALSE (eg CONSTANT Result = TRUE).

CONSTANT nvariable = number
CONSTANT wvariable$ = words

Note: Constants can only be defined outside of any functions, usually best placed at top of code for visibility




FOR
Loop through the code between { and } changing a variable from a start value to an end value. The way the variable changes can be by a specified step value each time, otherwise it will change by +1 if a step value is not specified.

FOR nvariable = nvariable|number TO nvariable|number
{
  ...
}

FOR nvariable = nvariable|number TO nvariable|number STEP nvariable|number
{
  ...
}

Note: FOR loops can only be used inside functions




FUNCTION
Define a new function whose code is contained between { and }.

FUNCTION funcname()
{
  ...
}

FUNCTION funcname(parameter)
{
  ...
}

FUNCTION funcname(parameter,parameter,...)
{
  ...
}

Note: Functions can only be defined outside of any other functions




GLOBAL
Define a new variable to be accessible from any function.

GLOBAL variable
GLOBAL variable,variable,...

Note: Global variables can only be defined outside of any functions, usually best placed at top of code for visibility




IF
Check a condition and if it is true run code between { and }.

IF wvariable$ = wvariable$|words
{
  ...
}

IF nvariable condition nvariable|number
{
  ...
}

IF test AND test ...
{
  ...
}

IF test OR test ...
{
  ...
}

IF ...
{
  ...
}
ELSE
{
  ...
}

IF ...
{
  ...
}
ELSEIF ...
{
  ...
}
ELSE
{
  ...
}

Notes:
- IF statements can only be used inside functions
- You can check more than one test in one IF or ELSEIF statement using AND and OR keywords
- You cannot mix AND's and OR's in one IF or ELSEIF statement, they must be all AND's or all OR
- You can have as many ELSEIF statements as you like
- IF/ELSEIF/ELSE statements can only be used inside functions




LET
Assign a value to a variable or perform operations on variables.

LET wvariable$ = wvariable$|words
LET wvariable$ = wvariable$|words + wvariable$|words + ...

LET nvariable = nvariable|number
LET nvariable = nvariable|number operator nvariable|number operator ...

Notes:
- Add words or word variables together to join them and make longer word sentances
- The operators are done in the order they appear in the code, just like a calculator would run them
- Local variables can only be defined inside of functions




LOCAL
Define a new variable to be accessible only in the function in which it is defined.

LOCAL variable
LOCAL variable,variable,...

Note: Local variables can only be defined inside a function




RETURN
Stop executing code from the current function and return to the calling function, or stop the app if the current function is START().

RETURN

Note: This statement can only be used inside a function




WHILE
While a condition is true and run code between { and }, checking the condition each time around the loop.

WHILE nvariable condition nvariable|number
{
  ...
}

WHILE test AND test ...
{
  ...
}

WHILE test OR test ...
{
  ...
}

Notes:
- WHILE loops can only be used inside functions
- You can check more than one test in one WHILE statement using AND and OR keywords
- You cannot mix AND's and OR's in one WHILE statement, they must be all AND's or all OR




Arrays
Arrays can be one dimensional or two dimensional.

One-dimensional arrays take the form variable[columns] and their elements are accessed using variable[column] where column is 1 to columns.

Two-dimensional arrays take the form variable[rows, columns] and their elements are accessed using variable [row,column] where row is 1 to rows and column is 1 to columns.

Both local variables and global variables can be arrays.




Comments
A comment is a line of code intended for the person reading the source code of the program. It doesn't change how the app works.

To start a comment line use // and the rest of the line is ignored by the app.




Function calls
To "call" a function (stop running code at the current position, run the called function code instead, and then come back to the current position when the called function finishes) you simply put its name on a line by itself followed by a pair of brackets.

If the function needs to be passed parameters then put these in the right order, and of the right type (numbers or words) inside the brackets separated by commas.

To ensure the program is as readable as possible function calls need to be on a line by themselves - they cannot be used in other statements like FOR, IF, LET, WHILE, etc.

For this reason if functions need to return a number they use the system global variable RETVAL, and if they need to return words they use the system global variable RETVAL$, and they can even use RETVAL and RETVAL$ to return both numbers and words. You don't need to declare RETVAL or RETVAL$ - they are declared for you by the YOUSRC runtime.




TRUE and FALSE
The values TRUE and FALSE are defined by the system ("enumerated") to have the values 1 (TRUE) and 0 (FALSE). You can use TRUE and FALSE in statements like CONSTANT, FOR, IF, LET, WHILE, etc in place of numbers.




Glossary
columnis a n number or number variable column index into an array starting at 1
columnsis the number of columns that should be stored in the array
conditionis one of the following
< (smaller than)
<= (smaller than or equals)
= (equals)
!= (not equals)
> (greater than)
>= (greater than or equals)
funcnameis a function name (eg AskPlayersAge)
nvariableis a number variable (eg Age)
numberis a decimal number (eg 42)
operatoris one of the following
+ (add)
- (subtract)
* (multiply)
/ (divide)
% (modulus)
parameteris a number parameter (eg Age) or word parameter (eg Name$)
rowis a n number or number variable row index into an array starting at 1
rowsis the number of rows that should be stored in the array
testis a test made by an IF or ELSEIF statement, either
wvariable$ = wvariable$|words    or nvariable condition nvariable|number
variableis a number variable (eg Age) or word variable (eg Name$)
wordsis a word string in quote marks (eg "hello world")
wvariable$is a word variable (eg Name$)






android, apps, toys, clipart, sound clips, games, wii, nintendo, ds, microsoft, apple, music, playstation, xbox, child, children, teen, music, school
Copyright (C) Previca Limited 2012
Note: This site is optimised for 1024x768 screen resolution.
Although many PC's and monitors support higher resolutions, many users of this site are schools who may not have the latest equipment.
If you are lucky enough to have higher resolution equipment then we are sorry you may see spare white screen space - we hope you understand.