Skip to content

4. Programming Language

Matej Vanco edited this page Oct 7, 2023 · 1 revision

Programming Language

Poly Engine offers its own programming language, written entirely in C#. It's an interpreted language, which means it's double-compiled: user-typed code > C# > CLR ... It has syntax and semantics that are exactly the same as Visual Scripting, but instead of connecting panels and elements, you will write the code yourself. If you are familiar with coding and programming in object-oriented / procedural / functional languages, this should be at least understandable for you. However, if you're not, you will get used to it very quickly due to its simplicity. Source programming in Poly Engine is private and closed off from external references, so you can't use any external libraries. The libraries are directly written in the built-in language. The syntax can be compared to Python or VBS.

Pros:

  • Simple to use
  • Quick to learn
  • User-friendly keywords and statements
  • Shortcuts
  • Just fine for prototyping

Cons:

  • Closed and private
  • Interpreted and no OOP (Object-Oriented Programming)
  • Very simple writing environment
  • Many essential statements are still missing
  • Partial issues
  • Very slow

Content


Language Essentials

Let's talk about the general rules & syntax. The language itself has certain limitations & user should be awared of it.

Syntactic General Rules:

  • Each line represents a 'one-block' of code. You can't use multiple statements in one line.
  • Statements and keywords do not require any ending symbols.
  • Unknown characters in blank lines are ignored by the compiler.
  • A blank line means 'end of the function.' To connect lines, use any character (as they are ignored).
  • Spaces between exact statements will be evaluated as a syntax error. Operations and parametric brackets ignore blank spaces.
  • In operations, use the marker NEG for negative number values. Example: @num>+50 - NEG24; means num + 50 - (-24).
  • Invalid naming characters are: ( ) { } ] [ ; " : | < > + - / * ! @ # $ % ^ & _

Syntactic Categories:

Variable Mentions

Variable mentions are used to 'mention' or 'include' an existing variable. The specific symbol is @. There are three types of variable mentions:
@VARNAME
@VARNAME;
VARNAME

  • The first pattern is used as a default example. @VARNAME is used in every engine-related function or in a variable assignment. Example: int v @num or if @n = 4 then... or @number>+24 - @number2 * @Num;
  • The second pattern is used in a Console-Output or in a text assignment only to make sure, where the variable ends - the ending mark is ; .
    Example: Console-Out you've got @percent;% and your mark is @mark;
  • The third pattern is used in a 'low-level' functions. Returnable extended statements use this pattern. It only uses variable names only. For Example: $Random(var1,var2)

Variable Connectors

Variable Connectors allow users to expand variable possibilities (length, object location, size...). The specific symbol for 'connection' is _ [underscore]. Formal example: @VARNAME_VarConnector • Informal example: @myvar_IsNum. More about the var connectors in Semantics.

Flexible Statements

Flexible statements allow users to use built-in statements related to the engine components, internal static values, constants etc. The specific symbol for 'flexible statement' is a bracket parameter at the end of the keyword (). Formal example: Statement() • Informal example: WindowWidth(). More about the flexible statements in Semantics.

Flexible Extended Statements

Flexible EXTENDED statements contain similar data as the statements above, the only different thing is the extended statements require some additional parameters. The specific symbol for 'flexible extended statements' is $ at the beginning of the keyword. All EXTENDED flexible statements do not tolerate mention mark @ inside the parametric brackets. Use a single variable name without any mention mark. Formal example: $Statement(Params) • Informal example: $Random(n1,n2). More about the flexible extended statements in Semantics.


Hello World

Let's write our first 'Hello World' in the code.

1. Variable Declaration

To declare any variable, use the default built-in syntax DATATYPE{SPACE}VARNAME{SPACE}VARVALUE. Spaces are very important and very required during the variable declaration. There are 5 types of supported datatypes: int, float, bool, string, object.

  • int (Integer) is a 32-bit signed numeric datatype
  • float (Floating Point) is a 32-bit signed decimal datatype
  • bool (Boolean) is a two-valued 8-bit logical datatype representing True or False
  • string is a collection of characters that is used to represent text (size may varies, string is immutable)
  • object is an additional built-in engine datatype that is used to allocate ~16-bit of memory for virtual objects in the engine editor

Example: string myName Matt or int myage 17 or bool trueOrFalse 1

2. Console Statement

Use Console-Out statement to output content to the console in the engine editor. The final console output after compilation can be found in the right corner. To clear the console content, use Console-Clear()

Example: Console-Out Hello World! My Name is @myName; and I'm lovin' it or Console-Clear()

3. Operations & Math

Math operations are pretty simple and linear here. It doesn't support 'bracket rules', so your operation will be straight-linear. Operations can be performed on existing variables only. Supported operations include Addition, subtraction, multiplication, division, and equation. To include a variable in an operation, use the 'mention' symbol @. For example, to get the value of PI, use $PI().
The syntax for operations is as follows: @VARNAME>OPERATIONTYPE OPERATIONVALUES; (Do not forget the semicolon symbol at the end to indicate the end of the operation)

Example: @myvar>+1 * 5 / 4 - @anynumericvar + $Round(numvar);

4. Arrays

Arrays (or pseudo-arrays) in Poly Engine can't be declared as a complete array object, but as a single variable of any datatype. The variable that's affected by the array algorithm must contain the character ^. Poly Engine offers a different structure for arrays (compared to what you might be used to in other languages), and the final declaration should be done within a cycle for.
Formal syntax examples: int var^i 0, string v^i helloWorld, or object obj^x obj^x.

Example:
int i 0
for>0>10
{
int num^i @i
@i>+1;
}
@i>=0;
for>0>10
{
Console-Out @num^i;
@i>+1;
}
(Output: 0,1,2,3,4,5,6,7,8,9,10)

5. Conditions

Conditions identify which statements should run and which ones should be skipped. You can use multiple parameters in one condition with different data types. Using multiple conditions inside statements is not allowed and will be evaluated as a syntax error. Possible condition operators include: > (greater), < (less), ) (greater or equal), ( (less or equal), = (equal [numeric]), - (equal [characteric]), ! (not-equal). Possible logical operators include: & ('and'), | ('or').
Formal syntax example: if{SPACE}VALUE1{SPACE}OPERATOR{SPACE}VALUE2{SPACE}then.

Example:
if @Number = @Number2 then
{
...
}

or

if Hello - @myName | @Number < 8 then
{
...
}
else {
...
}

6. Cycle For

Cycle For executes statements from a specific index to a specific length and allows you to loop through specific line blocks. Using multiple for cycles inside statements is not allowed and will be evaluated as a syntax error, just as using multiple conditions inside is not allowed.
Formal syntax example: for>STARTINDEX>LENGTH{ENTER}.

Example:
for>0>10
{
...
}

7. Custom Functions

Poly Engine allows you to customize your own methods and functions. You are able to create a function, 'call' a function, or 'jump' to a function. The difference between 'call' and 'jump' is as follows: if you 'jump to a function', the compiler will skip all the remaining lines and literally jump to the specific line to execute it. 'Call' will execute the function and continue compiling the remaining lines.
Formal syntax example:
[Create Function] {ENTER}-MyFunctionName{ENTER}
[Call Function] %MyFunctionName
[Jump To Function] #MyFunctionName.

8. Built-In Engine Statements

There are some additional statements that are closely related to the engine editor. All engine-related statements also contain flexible statements and flexible extended statements. For example, to create any object, use CreateObject statement. More about the language semantics can be found in the 'Semantics' section. To detect any key event, use KeyEvent(). There are plenty of statements that can be very helpful in creating simple apps. More information about the semantics is available in Semantics.

Clone this wiki locally