Skip to content

Fundamentals of the .uri Language

The .uri language is a simple programming language aimed at creating content for uri-core. Its main feature is that it is based on a tree structure, which allows hierarchical organization of the elements defined in the code. This is essential for designing a tree of possible interactions or behaviors for NPCs. Below, we explain the key concepts of the .uri language, its syntax, and its general operation.

Tree Structure in .uri

Node Concept

In the .uri language, each line of code is primarily composed of words, phrases, or numbers (all referred to as tokens). The first word in the line is the most important as it defines something specific, and what follows is extra information that complements it. Each line can be understood as a node. Here we have several examples:


Node Example #1

Code:

name welcome

Tokens: [name] [welcome]

Graphically:


Node Example #2

Code:

position -1056.683 4775.971 235.807 0.0

Tokens: [position] [-1056.683] [4775.971] [235.807] [0.0]

Graphically:


Node Example #3

Code:

say "Welcome to .uri!"

Tokens: [say] [Welcome to .uri]

Graphically:


Branch Concept

This tree is built as the code is written by relating all these nodes, where indentation (i.e., the number of tabs at the beginning of the line) determines the hierarchical relationship between the nodes, forming branches. The indentation of a new line must be less than, the same as, or one more than the immediately previous line. These are the 3 cases defined below.


  • Line indented the same as the previous one: They are considered siblings, meaning they are children of the same parent.

Relation Example #1

Code:

name welcome
model a_m_y_hipster_02

Graphically:


  • Line indented one more than the previous one: It is considered a child of the immediately preceding line.

Relation Example #2

Code:

    say "Welcome to .uri!"
        say "Where your dreams come true"

Graphically:


  • Line indented less than the previous one: It is a child of the same parent of another line that is equally indented.

Relation Example #3

Code:

interaction
    say "Welcome to .uri!"
        say "Where your dreams come true"

behaviour

Graphically:


Tree Concept

Once we combine all the examples, we can build a complete tree, which will be the basis for interpreting and creating our content. Let's see an example:

Code:

NPC

name welcome
model a_m_y_hipster_02
position -1056.683 4775.971 235.807 0.0

interaction
    say "Welcome to .uri!"
        say "Where your dreams come true"

behavior
    nothing

Graphically:

Use of Semicolon to Control Hierarchy

To avoid overly indented or pyramid-like code, .uri allows the use of a semicolon (;) at the end of a line. This semicolon indicates that the next line, even if it has the same indentation, will be interpreted as a child of the previous line, not as its sibling. For example, this code is equivalent to the one above:

NPC

name welcome
model a_m_y_hipster_02
position -1056.683 4775.971 235.807 0.0

interaction
    say "Welcome to .uri!";
    say "Where your dreams come true"

behavior
    nothing

Constructors

Constructors are fundamental elements in .uri. A constructor defines a new creation like an NPC, a quest, an item, etc. A constructor always starts with an uppercase word (for example, NPC), and its definition can include several attributes with different parameters that describe the characteristics or behaviors of this creation.

  • Attributes: Properties of the constructor that are defined on lines with the same indentation level as the constructor. For example, for an NPC, common attributes might include its position, name, model, etc.
  • Attribute parameters: Additional details that are defined following the attribute. For example, for the name, it would be welcome.

A single .uri file can contain multiple definitions of different constructors one after another, but an error interpreting the code of one constructor compromises the following definitions in that file.

A basic example of a constructor is what we have seen so far, defining an NPC:

NPC

name welcome
model a_m_y_hipster_02
position -1056.683 4775.971 235.807 0.0

interaction
    say "Welcome to .uri!";
    say "Where your dreams come true"

behavior
    nothing

General Syntax Principles

Respecting Indentation and Capitalization

It is crucial to respect both the indentation and capitalization of tokens and constructors in .uri. The language is sensitive to these characteristics, meaning that a variation in capitalization or incorrect indentation can change the meaning of the code or even produce errors.

Respect the required data for each field

To avoid runtime errors, it is essential to follow the documentation when placing a value as a parameter.

Comments, Spaces, and Blank Lines

The .uri language is flexible regarding line separation. You can include blank lines where necessary to improve code readability without affecting its functionality. You can also separate tokens by spaces within a line for clarity, but remember that full phrases must be enclosed in quotes if they are to be treated as a single token. If you start a line with //, you add a comment that will not be processed, which can help clarify the intention of the code.

Translation to Different Languages

The .uri language allows easy compatibility with translating any file into multiple languages. To implement this, there must be a file with the same name as the one to be translated but with the extension es.uriloc, where es is the language to be supported.

Everything that needs to be translated must appear in the .uri file as a single token without spaces in the form .example, where it always starts with a period followed by the ID assigned to the translation that will appear there. In the es.uriloc file, lines are added in the format where the ID comes first, followed by a colon, a space, and the string in quotes. In this case, it would be example: "This is a sample translation".