Rotur
  • Getting Started
  • Your Connection
    • What is a websocket?
    • Connecting
      • Handshake
      • SetID
      • Link
    • Authentication
      • Get User Data
      • Login
    • Rotur Designations
    • Websocket Commands
      • Global Message (gmsg)
      • Private Message (pmsg)
      • Login to rotur (auth)
  • My Account
    • Rotur Account Objects
      • originOS specific keys
    • Requesting my ofsf storage
    • Rotur Badges
    • Transactions and Taxes
  • Assorted APIs
    • rMail
    • avatars.rotur.dev
      • .banners
    • rotur.dev/auth
    • Keys
  • languages
    • RWL
      • Basics
      • Structure
      • Attributes
        • Text
        • Frame
        • Section
      • Alignments and Anchors
    • RTR
      • Basics
      • Structure
      • Functions
        • Mathematical Functions
        • String Functions
        • Array Functions
        • Object Functions
        • Logical Functions
        • Utility Functions
      • Events
      • Examples
    • RDF
  • Claw
    • What is claw
    • Api Endpoints
      • /feed
      • /post
      • /follow
      • /unfollow
      • /followers
      • /following
      • /profile
      • /delete
      • /rate
      • /following_feed
      • /reply
      • /repost
      • /top_posts
      • /search_posts
      • /search_users
  • Web Standard
    • What is this
  • Addons / Extensions
    • Basic Structure
    • Events
      • onload
      • page_load
      • page_focus
    • API
      • Classes
        • Page
          • (static) .new()
          • .getTitle()
        • URL
          • (static) .new()
          • (static) .parse()
          • .format()
          • .getAsyncData()
          • .getFetchUrl()
          • .getTitle()
    • Commands
      • redirect
      • opentab
    • Variables
      • tab_info
      • page_width / height
      • scroll_x / y
Powered by GitBook
On this page
  • Program Structure
  • Statement Types
  • 1. Variable Declarations
  • 2. Function Definitions
  • 3. Control Structures
  • 4. Function Calls
  • 5. Object Operations
  • Expression Structure
  • 1. Literals
  • 2. Operators
  • 3. Function Calls
  • 4. Property Access
  • Scope Structure
  • Event Structure
  • Function Structure
  • Error Handling
  • Best Practices
Edit on GitHub
  1. languages
  2. RTR

Structure

RTR is a lightweight scripting language with a simple but powerful structure. This document outlines the core components and structure of RTR code.

Program Structure

An RTR program consists of one or more event blocks. Each event block contains a series of statements that are executed when the event is triggered. Note that newlines have no syntactic meaning in RTR - they are purely for readability.

event (eventName) {
    /* Statements */
}

event (anotherEvent) {
    /* More statements */
}

Statement Types

1. Variable Declarations

variable = value;

2. Function Definitions

functionName = (param1, param2)~{
    /* Function body */
}

3. Control Structures

if (condition) {
    /* Code */
} elif (otherCondition) {
    /* Code */
} else {
    /* Code */
}

while (condition) {
    /* Code */
}

repeat (times) {
    /* Code */
}

for (variable, range) {
    /* Code */
}

4. Function Calls

result = functionName(arg1, arg2);

5. Object Operations

obj.property = obj.method(arg1, arg2);

Expression Structure

1. Literals

  • Numbers: 42, 3.14

  • Strings: "Hello", 'World'

  • Booleans: true, false

  • Null: null

  • Arrays: [1, 2, 3]

  • Objects: {key: value}

2. Operators

  • Arithmetic: +, -, *, /, %, ^

  • Comparison: ==, !=, >=, <=, >, <

  • Logical: !, ?

  • Assignment: =, +=, -=, *=, /=, ^=, %=

3. Function Calls

functionName(arg1, arg2);

4. Property Access

object.property;
array[index];

Scope Structure

RTR uses lexical scoping with the following rules:

  1. Global Scope: Variables defined outside any event or function

  2. Event Scope: Variables defined within an event block

  3. Function Scope: Variables defined within a function

  4. Block Scope: Variables defined within a scope block

/* Global scope */
globalVar = 42;

event (onload) {
    /* Event scope */
    eventVar = "Hello";
    
    function = ()~{
        /* Function scope */
        funcVar = true;
    }
    
    scope {
        /* Block scope */
        blockVar = 123;
    }
}

Event Structure

Events are the primary organizational unit in RTR. They follow this structure:

event (eventName) {
    /* Event initialization */
    /* Variable declarations */
    /* Function definitions */
    /* Main event logic */
}

Common events include:

  • onload: Triggered when the program starts

  • onclick: Triggered on mouse click

  • onkey: Triggered on keyboard input

  • ontick: Triggered on each frame/tick

Function Structure

Functions in RTR can be defined in two ways:

  1. Named Functions:

functionName = (param1, param2)~{
    /* Function body */
    return(value);
}
  1. Anonymous Functions:

obj.method = (param)~{
    /* Function body */
}

Error Handling

RTR provides basic error handling through the event system:

event (onerror) {
    /* Handle errors */
    log("Error occurred:", error);
}

Best Practices

  1. Use meaningful event names

  2. Keep functions small and focused

  3. Use proper scoping to avoid variable conflicts

  4. Use multiline comments for documentation

  5. Use built-in functions when available

  6. Handle errors appropriately

  7. Use proper indentation for readability (though not required)

PreviousBasicsNextFunctions

Last updated 25 days ago