Introduction:
Welcome back! In the last chapter of Essence of Block Code We talked about finding the block code menu, and briefly explained how each section worked.
I hope you enjoy this section, it shall be longer than the last.
The Chapters:
These are the chapters for “Essence of Block Code”. The bolded chapter is the one we will be talking about.
Chapter 1: An Introduction to the Interface
Chapter 2: Mathematics and Basics of the Essentials
Chapter 3: An Introduction to Variables and Logic
Chapter 4: Basics of Properties
Chapter 5: Applied Block Code!
Chapter 6: Logic and Applied Block Code
Chapter 7: Recursion and Loops with Block Code
Chapter 8: Advanced Usage of Properties
Chapter 9: Advanced Mathematical Operations in Block Code
Chapter 10: Text Manipulation
Chapter 11: Saving Blocks
Chapter 12: The World of Block Code
Key Words:
Parameter - The values you can input into a function. For mathematical functions, the parameters must be numerical.
Function - @getrithekd here. A function would take in an input, do some calculations on that input, and give you the output.
In this chapter…
We will be doing math! Yes, I know, math. But it can be pretty cool, and pretty fun!
Mathematics and Basic of the Essentials
Let’s talk arithmetic. Most people here are in middle/high school, so you all should be very familiar with the basics of mathematics.
I’m going to assume you all know a pretty good amount of math, feel free to ask any questions.
Anyways… how can we use gimkit to add one and two?
In the last part of Essence of Block Code, I mentioned a section in block code that can do exact math. Can you guess what it is?
That’s right! Mathematics! Pretty obvious. Let’s see what we can do. I hope you can open up the block code menu, and just a heads up, I will no longer tell you how to do it. Place down our favorite device. The trigger!
The trigger!
Open up the block code menu and go to the “Math” section! You’ll see all sorts of blocks here:
There are 7 types of blocks in the “Math” section.
Let’s give a quick rundown of what they are:
-
- Insert mathematical values into this block.
- [blank] + [blank]. Adds, subtracts, multiplies, divides, or exponentiates two numbers.
- square root. Performs exponential, logarithmic, and some other operations on numerical values.
- sin. Performs trigonometric operations on numerical values.
- [blank] is even. Check if a number is even, odd, prime, whole, positive, negative, or divisible by [blank]. Used with a logic gate.
- round. Rounds a number up or down.
- random integer from [blank] to [blank]. Generates a random integer from a lower bound to an upper bound.
Let’s try adding the numerical values 1 and 2 together. To place a block, all you have to do is click and drag the block into the menu, so let’s do that.
I added a plus sign!
You’ll notice that you can sort of “put” blocks into the plus sign. What does this mean?
Well, the sum of two numbers, in terms of code, is a function with two parameters. A function takes out one (or multiple) inputs called parameters and returns a value. For a more detailed explanation, look below.
An example of a function is division. It takes in the dividend and the divisor and returns the dividend times one over the divisor.
Definition of "function" and "parameter"
A function is just a block of code that takes an input, does something to it, and gives an output.
A parameter is something that you are allowed to put into a function, like a string, integer, or boolean (true/false value). This can vary with functions.
Parameters have limits. For mathematical functions, like addition, subtraction, and multiplication, the parameters cannot be text or true/false values (we will get into these later). We can only perform mathematical operations with numbers. Try multiplying the word “cat” by 3. What do you even think you would get?
For our plus function, let’s have the first parameter be 1, and the second parameter be 2.
Type in numbers by dragging the “0” block into the interface, clicking 0, and changing the text to whatever number you’d like by typing it in. You cannot set the number block to text, as text is not numerical.
We’ve added 1 and 2! But oh no! How do we get the result of our addition to show?
Well, there’s an extremely important block we can use, called the “activity feed” block. If you’re good at inference, you can probably tell that this “activity feed” thingy just makes something called a “feed” to show up.
Where is it?
You can locate it by clicking on the “Essentials” section.
We’re branching off of mathematics, but trust me - we will need this block in the future.
Activity feed!
What? There are three types of activity feed. What do we do?
If you’re familiar with scope, you might realize that this activity thing is just like scope! For now, add “Add Activity Feed Item For Everyone” to the interface.
Let’s connect blocks. Just drag the block to our equation and both blocks should snap into one bigger one!
Oh, wait…
You can’t do that. But why?
This is a very important lesson. The activity feed will only broadcast text. Then how should we get it to show a number?
The answer lies in the text section. Let’s go.
All the text blocks. Only 4, but whatever.
Can you find the block that will help us?
That’s right! It’s the “Convert Number to Text (With Commas)” block. Using this block, our number, “3”, suddenly becomes a string “3”!
What? How can a number be a string?
Well, this is kind of technical, but in this case, the number isn’t a number. It’s the text “3”. It’s not the number 3. Even though they look alike, one is a text value, and one is a numerical value. This is pretty confusing, but you do have to remember that you always have to convert numbers to text.
So, this is what your final setup should be:
The final setup. It doesn’t take up too many blocks. Hooray!
Wait, but how does the trigger get triggered?
Go to the settings of the trigger, and turn player collision on!
This way, you can simply step on the trigger and it runs block code. Great for debugging
Now, let’s test our setup.
Hooray, the number 3 showed up!
You can now add, broadcast on an activity feed, and more! Great work!
Let’s try dividing by 0:
Use the dropdown menu! Always check for a dropdown menu!
Infinity.
Experiment with some operations! Maybe you can even make a calculator! Who knows!
I think that’s pretty much it for math! We will go over some pretty advanced stuff later on in the series!
Remember:
Remember that Essence of Block Code is openly editable! That means that anyone can edit it! Feel free to add on what you’d like! You can even add stuff to the original section!
Conclusion:
Thanks so much for reading this! I hope you learned something!
-@mysz out.