RustlerScript | Variables, Integers, Functions, and Strings


Variables

An Introduction to Variables

Variables are one of the building blocks of learning a programming language. All programming languages have them, whether it is a dynamically-typed language or not (which RustlerScript is). Variables allow the programmer to create letter- or word-named items that can be used later in the code.

Adding and Assigning Values to Variables

In RustlerScript, assigning a variable is just like any Videos language; you would type the keyword "var", and then, with a space right after that, the name of your variable. However, RustlerScript limits your variable names to 50 characters, as well as preventing you from using spaces in variable names. In addition, regular variable names have to be typed like this: testVariableOne. You would have to have the first letter of the variable lowercase, and the rest uppercase, a rule in which most languages have.

Note

Prior to RustlerScript 12.0, variables were defined with parantheses and quotes. In RustlerScript 12.1, it is defined with just the universal "var".

Assigning values in RustlerScript is also very much the same as assigning variables in C#, C, Java, and JavaScript. However, Rustler's value policies are a bit stricter than that of Videos languages. In RustlerScript, you are limited to only have a numercial value, an object value, and a string literal.

Listing 1-1. Above, you can see two variables called testVariableOne and testVariableTwo, both assigned different numerical values.

Integers

An Introduction to Integers

Integers are also one of the msot common types of objects in all programming languages. However, RustlerScript has its own unique ways of describing them, unlike any Videos programming language.

In RustlerScript, you would normally define an integer by typing "int" (the keyword here) and then assigning it a class followed by an equals sign, and then identifying whether your new integer is an int16, int32, or int64. In addition, you would need to assign a name for your new integer. Right after the "int16, int32, or int64" attribute, you would put a comma, type "name", and then in quotes, the name of the integer. Below is an example of defining a regular integer:

Listing 1-2. Above, you can see an int32 with a name of myInt1.

RustlerScript has the same policy for naming an int as a variable: the first letter is lowercase, and anything after that is uppercase, an integer rule that is, once again, in most Videos languages.

Using Variables and Integers Together

RustlerScript allows you to use variables and integers together, meaning that you can have a value of a variable set as an integer name. Below, you can see this theory in action:

Listing 1-3. Above, you can see a variable called testVariable1 with two equal signs (meaning "is equal to an object/int/variable") and then a "new int" declaration. The keyword "new" is required here to make sure the compiler doesn't get confused and think that the variable is calling an already existent integer. After that, we declare that this new integer is an "int64", notice the Class attribute is uppercase, once again preventing the compiler from getting confused.

RustlerScript can get a little weird when it comes to assigning a new integer as the value of a variable. RustlerScript's ways of doing this have infuriated some programmers over the years after they have been with C#, C, C++, and JavaScript for so many years. This is one downside of RustlerScript.


Functions

An Introduction to Functions

Functions in RustlerScript have always been very easy to deal with, as it is a dynamically-typed language. Functions in RustlerScript are like functions in any Videos language, except there are some small details that RustlerScript has that is different from Videos languages.

RustlerScript's functions are different from that of Rust. Functions in Rust start with the unusual "fn main()". RustlerScript, however, is not like that. It declares functions with a "function" keyword, and then, after a space, the name of the function goes in parantheses. As always, the first letter of the function is lowercase, and anything following that is uppercase. Finally, on the next line, curly brackets open, as shown below:

Listing 1-4. Above, you notice that the name of this function is "addVariablesAndIntegers" which is wrapped in parantheses. Then, on the next line, curly brackets open. Inside of the function is a variable and an integer, the variable named "testVariable1" and the integer named "myInt1".

Working With Sub-Functions

In RustlerScript, there are more than one type of function. One is the main function, running the main variables and integers. However, there is a case when you might want to have a function inside a function. This is where sub-functions come in handy.

To define a sub-function, you would start with the regular "function", the name of the function in parantheses, but before the curly brackets, you would first type a comma, and then assign the class attribute. Type an equals sign, and in quotes type "sub-function". Finally, on the next line, open curly brackets. This is demonstrated below:

Listing 1-5. The first function is called addVariablesAndIntegers, and adds a variable called "testVariable1" and assigns its value to 50. Then, we create a new int64 and name it "myInt1". Then, the second function is addressed as "addMoreVariablesAndIntegers." Then, after a comma, the "class" attrbiute is used, displaying the function as the sub-function. This function adds a variable called "testVariable2" and assigns its value to 95. Then, it creates an integer that is called "myInt2".


Strings

An Introduction to Strings

Like any Videos programming language, RustlerScript includes the capability to create and name strings. Strings in RustlerScript are very much like integers, although they are mainly used for a sentence of text.

In RustlerScript, a regular string would have a name and content, which could also come many lines later in the code. To define a string, you would type the keyword "string". Next, type a double equals sign, and then the content of the string right after that in quotes. Remember, the first letter is always lowercase, while the rest is uppercase. After the name of the string, you may choose to write the content of the string (always one sentence, wtih no special characters) or you may choose to write it later. Below is a listing of when the content of the string is addressed immediatley:

Listing 1-5. Above, you can see that this string is called "myString1", and the name is immediately followed by the content of the string. This version shows how the content of a string is addressed immediately.

Listing 1-6. Above, you can see that on the first line, the string "myString1" is defined but not assigned a content. For the next couple of lines, the variables testVariable1 and testVariable2. Then, the string name is called, telling RustlerScript that you are calling the same string that you defined earlier. Then, you assign the content to the string which is "This is a string sentence.

Warning!

A string MUST be defined. Otherwise, the compiler will throw error R29263 and say "string content undefined."

Assigning String Values to Integers

RustlerScript allows you to assign an integer name of a string. This means that you can define a string for the name of an integer (any type will work.) RustlerScript is unique this way, as neither C#, C, C++, or JavaScript allows you to do this. Normally, to do this, you would first define the string and its content before defining the integer. You may not define the content after defining the integer. Below is the code for doing so:

Listing 1-7. Above, you can see that first, we define a string called "myString1" and assign the content to "Hello World." Next, we define a new int32. Then, we type a double equals sign (meaning that the integer is equal to another string, variable, or object) and do a callback of "myString1", the string we defined earlier. We open blank parantheses (used after making a callback) and end with a semicolon.