Loki Language Overview
Table of Contents
- Introduction
- Langauge Overview
- Types and Variables
- Control Structures
- Functions
- Files
- Functions vs. references
- Conclusion
Introduction
Welcome to the Loki language overview! This document provides a comprehensive overview of the Loki programming language, including its syntax, semantics, and features.
Language Overview
Loki is a statically typed programming language designed for building scalable and maintainable dialogue systems for any game engine or programming lnaguage out there. It is specially designed so it compiles down to a raw format that is understandabele by any programming language out there. The only thing that language has to be able to do is read and write text data.
At a high level, loki files have two main types of code. Dialogue, and Bracket Code. Dialogue is any plain text under a header, see here for info on headers, and Bracket Code is any code contained in [].
Loki uses a system similar to that of programming languages such as Java, C# or CPP. That system being that lines of code must have a semi colon at the end of it.
For example:
#HelloLoki:1
Greetings my friend! ;
You are looking great today! [Sound.Play("happy.mp3")];
You can see the header, dialogue, and bracket code all used in this example loki script.
Keywords
Loki uses many of the same keywords that you would find in many other programming languages. It has some of the basic variable types such as int, bool, and string, while also having some more advanced keywords like using.
Here is an over view of each keyword and its use case:
Integers represent whole numbers in loki. They are primarily used to define the type in functions. See below for an example on how it may be used
#ExampleFunctions(int exInt)
String represent variable text in loki. They are primarily used to define the type in functions. See below for an example on how it may be used
#ExampleFunctions(string exString)
Booleans represent true or false in loki. They are primarily used to define the type in functions. See below for an example on how it may be used
#ExampleFunctions(bool exBool)
Literals
Loki provides many options that enable you to write cohesive dialogue. It structures things at a File -> Header -> Code system.
Headers
Headers are the parts of the code that hold dialogue and code. Any code that is inside of them gets run one line at a time. Lines are determined by a semicolon. In order to run the next line of code, the integration package has to request it from the current header. If you need other options, see the functions here: Functinos
To learn more about headers, see below:
#ExampleHeader:1
You begin with a # symbol followed by the header name, then the variation id. The variation id is the part which determines which variation of the header should be played once the name is called. For example:
#ExampleHeader:1
//Some code
#ExampleHeader:2
//More code
#ExampleHeader:3
//Even More code
In this case, if you were to call #ExampleHeader, it would begin with the first variation. Then, if you call it again, it would begin with the second variation and if you called it again, it would begin with the thrid variation. If you reach the final variation and call it again, it would repeat the final variation.
If you find yourself in a place where you need to call any other header than the order followed by the variations, you can run the following code:
[#ExampleHeader:1]
This will call the first variation of #ExampleHeader regardless of the current variation. This also allows you to start other headers while you are in a different header.
For example:
#HelloWorld:1
Hello, World! ;
Welcome to Loki! ;
#HelloWorld:2
This is the second variation. ;
It also starts the GoodByeWorld header ;
[#this.GoodByeWorld:1]
#GoodByeWorld:1
Good Bye, World! ;
You've been a great crowd! ;
This code will run through the HelloWorld Headers untill it reaches the second variation. After displaying the text, it will run the code [#this.GoodByeWorld:1] to call the GoodByeWorld Header. This will immeadiatly run and display/run any thing that is found in the called Header.
One thing to note is that loki supports cross referenceing files. You have the ability to call another header or function in a separate file. More info here: Files.
Functions
Functions work much like the headers but they are used to group code together that gets run all at once, in one single request. This differs from headers, found here: Headers
to learn more about functions, see below:
#Print(string message)
[@System.Print($message)] ;
In this code, we declare a function Print. Note that it uses a similar syntax to the header, the only difference being it has parenthesis instead of a collon and variation id.
In order to call this function, you would insert this code into a header: [<file>.<functionName>(<parameters>)]
Here is an example of it in an actual loki file:
#HelloWorld:1
Hello, World! ;
Welcome to Loki! [this.Print("Ended Variation 1")];
#HelloWorld:2
This is the second variation. ;
It also starts the GoodByeWorld header [this.Print("Ended Variation 2")];
#Print(string message)
[@System.Print($message)] ;
Note how we use the keyword this. This keyword tells loki that the function we are calling is in the current file and there is no need to look elsewhere for it. For more details on files and libraries, see here: Files
Files
Loki uses a project structure similar to that of other programming languages such as C# or Python. You can call headers and functions in other files than the current one via the code [<file>.<function>(<parameters>)] for functions, and [<file>.<header>:<variationID>] for headers.
In order to call a function or header in another file, this file must be imported at the toop of the loki file.
For example:
/*************
*Loki_01.loki
*************/
[using File_02]
#HelloWorld:1
Hello, World! ;
Welcome to Loki! [File_02.Print("Ended Variation 1")];
#HelloWorld:2
This is the second variation. ;
It does stuff [File_02.Print("Ended Variation 2")];
/*************
*Loki_02.loki
*************/
#Print(string message)
[@System.Print($message)] ;
This allows you to keep your code organized and modular.
Function Calls vs. Reference Calls
In Loki, there are two ways to call code from other headers or files: function calls and reference calls. Understanding the difference between these two methods is essential for creating efficient and well-organized code.
Function Calls
Function calls are used to execute a specific function or method within a file. When a function is called, the code inside the function is executed, and the function may return a value. Function calls are denoted by square brackets [] and the function name, followed by parentheses containing any required arguments.
For example:
[this.Print("Hello, World!")]
In this example, we're calling the Print function from the current file (this) and passing the string "Hello, World!" as an argument. The function will be executed, and the string will be printed.
Reference Calls
Reference calls, on the other hand, are used to call code in the actual programming language your game is running on. When a reference call is made, the Loki code execution is paused, and the reference call is passed directly to the integration package, which then executes the code in the target language.
Reference calls are denoted by square brackets [] and an at sign @, followed by the target language's code.
For example:
[@Console.WriteLine("Hello, World!")]
In this example, we're calling the Console.WriteLine method in the target language (e.g., C#). The Loki code execution will be paused, and the reference call will be passed directly to the integration package, which will then execute the Console.WriteLine method.
It's important to note that reference calls can only be used to call code in the target language, not functions or headers within Loki files.
Understanding the difference between function calls and reference calls will help you write more efficient and organized Loki code.
Conclusion
Thank you for reading the Loki language specification! We hope this document has provided you with a clear understanding of the Loki programming language.