Skip to content

Functions

Functions in CES are used to group instructions into reusable blocks of code.
They help organize scripts, reduce repetition, and make code easier to maintain.

A function can contain variables, conditions, loops, and other function calls.

Declaring a function

To declare a function, use the func keyword followed by the function name and a block of code.

Example:

func SayHello()
{
    DisplayLog("Hello World");
}

Calling a function

To execute a function, simply write its name followed by parentheses.

Example:

SayHello();

Expected output

func example

Function with parameters

Functions can also receive values as parameters.

Example:

func ShowMessage(Str text)
{
    DisplayLog(text);
}

ShowMessage("Welcome");

Expected output

func parameter example

Function with return

Functions can return values using the return keyword.

To define the return type, place : Type after the parameter list.

func Areacircle(Float ray): Float {
    return 3.14 * (ray * ray);
}

Calling the function:

DisplayLog(Areacircle(10));

Output:

314.0

Note

If a function declares a return type, it should return a compatible value.

Complete Example

func GetMessage(Str name): Str {
    return "Hello " + name;
}

String msg : GetMessage("Ana");
DisplayLog(msg);

Output:

Hello Ana

In this example:

  • GetMessage receives one parameter (name)
  • the function returns a String
  • the returned value is stored in msg
  • DisplayLog prints the result ```