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.
Statement Types
1. Variable Declarations
2. Function Definitions
3. Control Structures
4. Function Calls
5. Object Operations
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
4. Property Access
Scope Structure
RTR uses lexical scoping with the following rules:
Global Scope: Variables defined outside any event or function
Event Scope: Variables defined within an event block
Function Scope: Variables defined within a function
Block Scope: Variables defined within a
scope
block
Event Structure
Events are the primary organizational unit in RTR. They follow this structure:
Common events include:
onload
: Triggered when the program startsonclick
: Triggered on mouse clickonkey
: Triggered on keyboard inputontick
: Triggered on each frame/tick
Function Structure
Functions in RTR can be defined in two ways:
Named Functions:
Anonymous Functions:
Error Handling
RTR provides basic error handling through the event system:
Best Practices
Use meaningful event names
Keep functions small and focused
Use proper scoping to avoid variable conflicts
Use multiline comments for documentation
Use built-in functions when available
Handle errors appropriately
Use proper indentation for readability (though not required)
Last updated