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:
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
/* 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 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:
functionName = (param1, param2)~{
/* Function body */
return(value);
}
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
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