The Basics
On this page, we go over the basics of Radon, and at the end show an actual functioning plugin. But first, check out the tutorial!
Getting started:
Adding the Radon plugin to your VSCode
Download the .zip file. You can download it here.
Put the .zip file in
%userprofile%/.vscode/extensions
Extract the .zip file in
%userprofile%/.vscode/extensions
Now any .rd file you open with vscode will have syntax highlighting accordingly.
String swapping
Before we get into any examples, there are key concepts that need to be covered.
Archives
What are archives?
An archive is a stream of bytes, that represents an open asset. Archives can be read from, written to, and swapped.
There are two types of archives: from_ar
and to_ar
.
Syntax
You can import archives by using the following syntax:
Note: Replace [Archive]
with the archive you want to import. i.e from_ar
or to_ar
.
Directives
Directives are compiler instructions; they begin with a #
. Directives tell the compiler what to do during compilation.
Types of directives
Currently, there is only one type of directive which is the file directive.
The File directive
The file directive tells the compiler what type of file it's dealing with.
The file directive has two operands: plugin
and code
.
The plugin
operand tells the compiler that it is dealing with a plugin
file and thus should allow top-level-statements.
Syntax
Signs
Signs are a special feature that allows you to sign your plugin, so that you get the credit that you deserve.
Special Signs
In Radon, signs are dynamic, meaning that within the key-value pairs, you can technically put anything, however, only a few signs have meaning.
Author
Is the original creator of the plugin and can be seen on the plugin in the swapper.
Name
Is the name of the plugin and can be seen on the plugin in the swapper.
Icon
Is the icon of the plugin that is displayed in the swapper.
Rarity
Is the rarity of the item that you’re swapping.
Series
Is the series of the item that you’re swapping.
Encryption
Is used for marking the encryption method. This can be set to either True or False.
Syntax
Method Calls
A method is a block of code that performs a specific task and can be called from other parts of the program. This eliminates the need to continuously rewrite the same code.
Special Methods:
There are a few special methods that are built into special types that are part of the runtime.
The methods are the following:
Type: archive
Read<T>()
Write<T>(T value)
Seek(int offset, seek_origin origin)
Seek(string str)
Swap(archive other)
Type: system
Print(string text)
Syntax
Static vs Instance
In Radon, there is an access modifier with each method. There are static and instance methods. These modifiers determine in what context you're allowed to call these methods. You may ask: "What does static and instance mean?" In Radon, "static" and "instance" are terms used to describe the characteristics of struct members, such as fields and methods.
A static struct member is associated with the struct as a whole, rather than with a specific instance of the struct. This means that a static field or method can be accessed directly from the struct, without the need for an instance of the struct to be created first.
An instance struct member, on the other hand, is associated with a specific instance of the struct. An instance field or method can only be accessed through an object of the struct, and different instances of the struct can have different values for their instance fields.
We will get into fields when we cover structs and enums.
Static and Instance calls syntax
Generics
In Radon, generics are a way to create a method that can work with multiple types of data, rather than being tied to a specific type. This allows for more flexibility and reusability of code.
Types
In Radon, a type refers to the category of data to which a variable or expression can hold or evaluate. Types can be divided into two main categories: value types and reference types.
Members
Members belong to types. They can be either static, or instance which we discussed earlier.
Types of members
Currently, there are four types of members: methods
, fields
, constructors
, and static constructors
.
Methods, which we discussed earlier, are blocks of code that can be called multiple, eliminating code duplication.
Fields contribute to the overall structure of a type. The sequence sum of all fields within a type, adds up to the entire memory an object takes up.
Constructors are special methods that are called when creating a new object using the new
keyword. They are used to initialize instance data.
Static Constructors are special methods that each type contains. They are called when the runtime first runs, and initialize all static data. These cannot be explicitly called.
Objects
Simply put, an object is an instance of a type. An object is what you pass in as an argument to a method, or what you use when you want to call an instance method.
Creating objects
To create an object, you can use the following syntax:
Type variable = new Type([Arguments])
Example
Comments
You can make your code cleaner, and make more sense by using comments.
Syntax
Time to code
Now that you have all of this information, you're probably wondering what to do with it.
Below, I have created a plugin that demonstrates many of the features that we have discussed. This code is also explained in the tutorial, which you can find at the top of this page.
When swapping multiple strings in an asset, make sure to sort them from longest to shortest string. This helps with the data-pooling process in Saturn Swapper. Strings may be incorrectly overwritten if you don’t.
Last updated