In this tutorial, I will teach you how to make a very simple E2, where the output value changes, which relies on addition and subtraction. I'll put the full code first, and then explain everything after. Here is the code:
Notice in this code, I don't use the "runOnTick(1)" command, as I do not want the expression to check itself with out the player pressing a button. The things you will need for this tutorial are:
- - Screen
- 2 Buttons (non-toggle)
Now, I'm not going to go over the "@name", "@inputs", and the "@outputs" because I have gone over those in some of my other tutorials. As you can see, this expression runs off of two simple lines of code. The variables: "Add" and "Subtract" are the buttons, and "Screen" is the screen. I'll break down the first line for you.
if(Add == 1 & Screen >= 0 & Screen <1000){Screen+= 1}
What this is saying is; that if the "Add" button equals 1 (==), and the "Screen" is larger or equal (>=) to 0, and the "Screen" is smaller than (<) 1000, then the "Screen" will add 1 (+=) to it's current value.
if(Subtract == 1 & Screen > 0 & Screen <=1000){Screen-= 1}
This code is almost the same, except that it subtracts 1 from the current value instead of adding 1. I'll go over it anyways; If the "Subtract" button equals (==) 1, and the "Screen" is larger than (>) 0, and the "Screen" is smaller than or equal to (<=) 1000, the "Screen" will subtract 1 from it's current value (-=)
Wiring!
Wiring this up is fairly simple. Wire the "Add" and "Subtract" from the E2 to the 2 buttons, and the "A" from the screen to the "Screen" on the E2. If everything is done correctly, you should see that the screen displays a 0 as the value. When you press the add button, the screen will go up a value, and will go down when the subtract button is pressed.
This E2 can be helpful in many ways, such as cycling through teleporter locations, and other things. I'll be making more E2 tutorials, so don't forget to to watch me!
In case you lack the mental power to wire it up properly, here a video on how to wire it up.