top of page

Blocks

Building Blocks

Those blocks are what's going to compose the structure of your creation. These comes in various shapes, one cube, a floor, a wall and a currently not available stair block. To place same, hold the building key, [Tab], and click on your secondary mouse click, usually set to right by default. To delete them, use the primary mouse click, usually set to left by default. Easy. Now, to change block type, use your scroll wheel while holding the building key. Beware that the first block that you place on the ground will be the root block. Each time your place a new block on the same structure, it gets attached to the root block. But if you delete that root block, all the others attached to it gets deleted.

Coding

Need some more help? Join the discord server!

Basics and functions

ConsoleBlock's unique coding language is pretty simple to understand. I'll do my best for you to explain how it works. Let's look at a simple code snippet and learn what each part does.

void Update () {

   if(Button.GetButtonDown) {

      ServoMotor.SetConstantSpeed(1.0);

   }

   if(Button.GetButtonUp) {

      ServoMotor.SetConstantSpeed(0.0);

   }

}

It looks complex but in facts it's pretty simple.

 

To define which line of code will be executed with what other line in what group in what order you need to group them. For that you need to define a function. Functions usually start with the keyword void followed by the function's name. After that always put empty parentheses, I'll explain that later. The code that will will be executed when calling the function is defined by to brackets. Notice how each bracket pair increase or decrease the amount of tabs (a.k.a big spaces)? That helps us, humans, know which line of code are part of what brackets group. By the way, never put any function inside an other function. That won't work. (Honestly I don't know what will happen if you do that)

 

Wondering what the stuff inside? Those are example of lines of code. Look at the next section. Last VERY important thing. Why did I choose Update for my function name? Because no mater what, this function will be automatically refreshed every fraction of a second to keep all your blocks up to date.

Variables and lines of codes

In this section let's learn what are the line of codes present in this code snippet and in various other examples to learn what they do how they work.

if(Button.GetButtonDown) {

   ServoMotor.SetConstantSpeed(1.0);

}

if(Button.GetButtonUp) {

   ServoMotor.SetConstantSpeed(0.0);

}

You should read the block tutorial before moving on to this section. -- Let's start with something important here; what are the (currently available) value types.

 

First we got boolean, known in code as bool. This value type can represent a value of either false or true (Can be view as open or closed, yes or no but those value won't work in the code).

 

After that we have two number value types. int are integral numbers, in other words, natural none-decimal numbers. It can be represented simply as an number composed of digits without any decimal points such as 12093 or 3. It can also be negative. For example -182. Pretty easy to understand right?

 

The second number type are float. Float are similar to ints but they are decimal instead of being natural. When you are required in the code to use a float, make sure to always put a decimal point no matter if it need it or not as seen by the example at the top.

ServoMotor.SetConstantSpeed(0.0);

​

The last two value type are less used but we are going to only see the string for now. Strings are text values that can be used for example, displaying text on screen. In code, to define a string, write any text surrounded with two "".

​

If you want to create a temporary variable that can remember a certain value until the brackets group ends, create a local variable by writing the value type's keyword followed by the name of the variable (All names, including block names and variable names, can only contain letters, digits and underscores _), a equal sign to tell the script what's going to be set as it's initial value and the value followed by a ; sign to show that the line as ended. Remember to always tell the program when a line ends. This is not needed when the line ends with a code block, also known as brackets {}.

The final variable declaration line should look like this: int MyFavoriteNumber_145 = -78;

​

Now that's done let's take a look at various code line types and see their function and uses.

ServoMotor.SetConstantSpeed(1.0);

This line calls block linked to the console's input, named ServoMotor, and tell it to execute a function names SetConstantSpeed. The autocomplete function of the console allow you to find blocks linked to the input, what function and variable they have and what are its parameters. To find out what each function does, guess it by taking a look at the carefully chosen names or check in the block wiki of the learn more about the game section of this website.

​

Blocks have not only functions but they also have variables that be read and, rarely, written. To write over a block variable to change its value, mention the variable followed by an equal sign and the new value you want to set it to. Take a look at this example: 

DigitalBattery.MaxPPSOutputing = (ServoMotor.CurrentRotation + 3.0) / 36.0;

As you can see, you aren't obligated to use already prepared values. You use variable that you read and pass trough operation signs to transform it.
 

Now, let me present you the if gate. It only execute the code block if it's parameter is a boolean of type true.

if(Button.GetButtonUp) {

   ServoMotor.SetConstantSpeed(0.0);

}

Expend it by using the else keyword. Put it after the closing bracket. I will only execute it's code block if the if gate failed.

if(Button.GetButtonPress) {

   ServoMotor.SetConstantSpeed(0.0);

} else {

   ServoMotor.SetConstantSpeed(1.0);

}

You can alternatively combine the two by using else if. It will only execute its code block if the first if failed and its parameters is equal o true. You can also combine multiple of those.

​

In the next section, we're going to see even more flow gates like if, else and else if and see more operation option like we saw earlier.

Operations and flow gates

In this section let's learn how to do an equation and what are the currently available flow gates and how do they work.

if(Button.GetButtonDown) {

Let's begin by seeing all the operators in order. But first here's a important rule to understand:

If there's multiple operation with the same amount of priority, the one that is most to the left will be calculated first.

​

Parentheses Operator ( )

A group of parentheses encapsulate any operations inside it and give priority to it. Let's take a look at this line for example. (4 + 5) * 9 Without the (), the execution would do 5 * 9 +4 because multiplication has a higher priority than addition.

​

Negative Operator -

To not be mixed with the subtraction operator. This operator works only on number variable types like floats and ints. It simply negate any number. You can also put it in front of variable calls like this: -ServoMotor.CurrentRotation. Cool Uh?

​

Rounding Operator #

Rounds a number and convert it to an int.

​

Not Operator !

Flips boolean only. Turn false into true and true into false.

​

Multiplication, Division, Modulo Operator * / %

Works only for number variable. The first two are self explanatory. Modulo is a division but instead of returning the divised number, it returns the remaining part of the division. Take a look at this example: 12 % 5 [can be reprensented by] = 12 - 5 - 5 [which equals] = 2 

or

3.75 % 0.5 = 3.75 - 0.5*7 [7 reprensents the amout of times 0.5 can fit into 3.75] = 0.25

​

Addition, Substraction + -

1 + 1 = 2 or 5 - -5 = 2 Easy stuff. It can also combine string with other string or string w/ individual char. "Bottom " + "Text" = "Bottom Text"

​

Number Comparaison Operator < > <= >=

You probably guess it, it's for numbers only. These operator and made to compare the size of numbers. In order: Smaller than, Bigger than, Smaller or Equal, Bigger or Equal

​

Equal or Not Equal Operator == !=

Compares if two variables, not only numbers, are the same or different. Make sure to put not ONE but TWO equal sign one next to another for the equal operator.

​

AND Operator &&

Returns true if the two boolean on each side are true.

​

OR Operator ||

Returns true if the on of the two boolean on each side is true.

​

Side note for advanced developpers

C# Binary Operators are available. Check Microsoft's website to know their order. You can also suggest new operator in my discord server.

​

What were we supposed to talk about. Let me check in the script.

Oh. Flow gates.

​

The following section will show some keywords used to control the flow of the execution of the line. For example, loops can repeat a certain code block a certain amount of times.

​

Did you know that function were also able to return a value after being executed? Instead of using void as the function keyword, use the variable keyword of the value you want to return. Every none-void function needs to have in every path a return keyword. This will automatically end the function and return the variable after it. If return is executed in a void function, it will simply end the function without returning anything. Example time: 

​

void Update () {

   if(Button.GetButtonDown) {

      ServoMotor.SetConstantSpeed(CalculateStuff(3,4));

      return;

   }

   ThisShouldNotBeExecutedIfTheIfGateAboveWasExecuted();

}

​

int CalculateStuff (int x, int y) {

   return (x + y) * y;

}

​

Notice anything new? These parentheses after the function serves have some kind a purpos. You can add functions parameters to a function. This should be enough self-explanatory at this point.

​

After that we got loop. There are currently only two kind of gates: the for loop and the while loop. Let's begin with the less useful but simpler one: The while loop. This loop will repeat its code over and over and over until its only boolean becomes false.

​

if(Button.GetButtonDown) {

   ServoMotor.SetConstantSpeed(0.0);

   while(!Button.GetButtonUp) {

      

   }

   ServoMotor.SetConstantSpeed(1.0);

}

​

This small code snippet execute only if the button gets pressed. If it does, the servo moter speed gets set to 0. The while loop will pause the script until GetButtonUp gets updated to true. The not operator will turn this true into false and allow the following line to be executed and sets the speed back to one. 

​

The for loop has 3 parameters, the first one will be executed at the initiation. This line can be whatever instruction you want it to be, for example, a variable declaration, the second needs to be a boolean. It will decide whenever the loop should continue, true, or stop, false. This boolean is checked BEFORE executing the code block. The last parameters is can be any instruction. It will be executed after the code block. For example, if you want a loop that will execute the same line 5 time, write:

​

for(int i = 0; i < 5; i++) {

   LineOrCodeThatYouWantToExecuteFiveTimesHere();

}

​

Remember that we always start counting from zero. At each iteration, 'i' will be:
0, 1, 2, 3, 4.
It will never ever reach 5. Deal with that

​

You can also control loops using two simple keyworkd: continue; break;

Continue just skip the current iteration of the loop and break, well, it breaks the whole loop and go to the next line under the loop.

​

​

This section is over now. Hope you understand at least a little part of it. Goodbye!

bottom of page