Detailed Terraria API training from StarLife Team

Detailed Terraria API training from StarLife Team

The guide is written for people who are already at least a little familiar with the C # language and have experience with tModLoader

Modifiers

Show / Hide text
Modifiers are used to change type declarations and their members.

Some of the most popular modifiers are access modifiers, which are responsible for the security level of your method or variable.
There are 4 access modifiers in total:

1) -public is a public modifier that allows you to use a class, method or variable in other files or methods:
public static int hungerscore = 350; // public variable that can be used in other methods.
Hunger.Hunger.hungerscore + = 15; // so we can use hungerscore in other files.

2) -protected is a protected modifier that prohibits the use of a class, method or variable in other files.
protected static int hungerscore = 350; // protects our variable
Hunger.Hunger.hungerscore + = 15; //error

3) -private is a private modifier that gives you the minimum permission to use a class, method or variable.
public void Employee (); //method
{
private int i; // variable can only be used in this method
}

4) -internal is a modifier that is used only for types and members of types.
public void Base ()
{
internal static int x = 0; // internal type or member is only available inside files in the same assembly
}

-const is a constant modifier indicating that the value of a variable cannot be changed using this modifier.
-event - a modifier declaring an event (not invasions)
-extern is a modifier indicating that the method has an implementation
-override - a modifier providing a virtual member implementation
-unsafe is a modifier that declares an unsafe context
-virtual - a modifier that declares a method or accessor, the implementation of which can be changed
-new - modifier hiding a member inherited from the base class
-sealed - modifier indicating that the class cannot be inherited
-static - a modifier used to declare a static member that belongs to the type itself, and not to a specific object

In addition to these modifiers, there are readonly, volatile, abstract, async, which are used less often than others.
// Implementation is the result.
// // - a comment.

Types of Variables

Show / Hide text
sbyte - from -128 to 127

Used to declare variables with a very small value, this is how variables are declared:

sbyte VariableName;
VariableName = value;

byte - from 0 to 255

Variable type with a range from zero to 255, example:

byteName;
Name = 25;

char - from U + 0000 to U + ffff

Not used

bool - true or false

It is used most often when denoting the veracity of a value, for example:

boolName;
name=false;

Here, I have declared the variable Name with type bool as false. This type is often compared to a binary code.

short - from -32768 to 32767

Variable type with also a small range, example:

shortName;
Name = 40;

ushort - from 0 to 65535

Variable type similar to short, but with a range from zero to 65535, example:

ushortName;
Name = 0;

float - numbers with percentages (± 1,5 * 10-45 to ± 3,4 * 1033)

Percentage value, usually used like this:

floatName;
floatName2;
floatName3;

Name = 6f;
Name2 = 7f;
Name3 = 8f;

Name * = 0.9f;

Multiplies the value of the Name variable by 0.9℅

Name2 + = 4f;

Add 4℅ to Name2

Name 3 - = 7f;

Subtracts 7℅ from the value of the Name3 variable

You should also always write f when declaring a variable value of type float, otherwise it will generate an error of incorrect conversion to type double

ulong - from 0 to 18446744073709551615

This is the same long type, but with a range from zero to 18446744073709551615, usually such large values ​​are not used properly, but can be used for example for frenzied damage, for example:

long Damage;
Damage = 18446744073709551615;

long - from -9223372036854775808 to 9223372036854775807

This type is needed if you want to declare a variable with a very large value, for example 10 billion damage, it is declared just like other types of variable numbers.

longName;
Name = 10000000000;

uint - 0 to 4294967295

This type is needed to declare variables with a value of 0 or positive numbers up to 4294967295, for example:

uint Name;
Name = 0;
uintName2;
Name2 = 40;

int - from -2147483648 to 2147483647

The most common type for variable numbers, example:

intName;
Name = -150;

Or

intName;
Name = 150;

You can also use math in variable declarations using the + - * / signs, example:

intOne;
int two;
int three;

One = 1;
Two = 2;
Three = One + Two;

It also only applies to variables of the same type, which is logical.

These variable names were used only for convenience, you can use your own names, but only in English and without spaces.

Conditions and cycles

Show / Hide text
1)
The most common operator is if-else.
The if statement determines which statement will be executed when the condition is met:
bool Read = true; // variable is set true
int i = 0; // i = 0

if (Read) // if read = true; then ...
{
i ++; // add one to i
}

else // otherwise ...
{
i + = 0; // leave i unchanged
}

2)
A less commonly used operator is the - for loop
Using a for loop, you can loop through a statement or block of statements:

for (int i = 0; i <10; i ++) // execute the command 10 times {Main.NewText ("Hi, World!", 255, 255, 255); // display the message "Hi, World!" } // if the value is less than 10, then the loop = true; if it exceeds 10, then the loop = false; 3) Operator while: The operator "while" executes a statement or block of statements until the specified value is reached the limit: int n = 1; // n = 1 while (n <6) // while n is an expression declaration // In addition to these operators, there are other operators, but they are more difficult to use [/ spoiler]

The official group of the StarLife Team VKontakte
(We have armor with a change in characteristics, a hunger system, the transfer of Retribution of The Darkness to tModLoader, and many other interesting things 

e152
TerrariaGo - Everything for Terraria (Terraria) free download