Now before we begin I would like to stress out the term basic. If you know basics this is not for you.
For any others you have come here seeking help from taking that first step and is too lazy to search for tutorials on your own.
I am trying to dumb down any tutorials I find with my own logic with an imaginary Noob for my amusement and make things easier.
I am also open to suggestions from anybody and I hope you learn something.
Resolute's Basics
Section 1
<Noob>"lern meh e2 plox"
Alright then let us start.
@name
@inputs
@outputs
@persist
@trigger all
This is what you see if you spawn an empty E2 chip.
@name - This is where you name the E2 chip your gonna make, you can leave blank if you want and its gonna show up as like "(generic)" when you point at it.
@inputs - This is where you declare inputs
@outputs - This is where you declare outputs
@persist - This is where variables that aren't inputted or outputted are declared
@trigger all - This is what triggers the E2 AKA what starts it. In this case it would be everything, hence the "all" but this can be modified for just one or two inputs. There are also different ways for starting the E2.
<Noob>"whut?"- Dont worry I'll explain later, same for persist mkay?
So let us make an easy E2 that can be used to open a door. It will be called "Door" and takes an input of 2 non-toggling buttons that outputs 1 for on and 0 for off which I will call "Button1" and "Button2".
Considering that the door is a hydralics-slider type, the E2 is going to output the length of the hydralics to the controller that will open or close the door which I will call "Length".
Since I don't need any other variables and the ones I have now are inputs and outputs (Button1,Button2,Length), @persist is not required.
The @trigger will also be demonstrated in ways it could be used.
<Noob>"but hao mak hydra-slide dor?"-I assume you would have basic building skills but your a noob so.
______ ______
| Wall |----| Hydra and slider|----| |
| | <-------- Close | Door| (awesome picture)
|_____ | Open-----------> |_____|
________ ___
|controller|<----------|E2|
---------- ----
(B1) (B2)
@name Door
@inputs Button1 Button2
@outputs Length
#@persist
@trigger all
<Noob>"wat dus # men at frunt of teh @persist?" That just means that after the # anything else that is written after it on that line only ceases to be code and becomes something like a comment such as.
@name Door #Google tutorials noob
The name of the E2 will not be "Door #Google tutorials noob", just plain "Door"
So now wire everything up. Controller is input and accepts an output from the E2 of Length. So use your wire tool and shoot the controller than the E2. The E2 itself accepts two inputs from two buttons. So we shoot the E2 then one of the buttons. Now point at the E2 again and hit right-click, make sure that the little box that is showing now says Button2, shoot the E2 and then the other button.
<Noob>"wher find wire tool?" ...Anyways, moving on
<Noob>"wait, i finds it"
On to the coding part hurray! Let me also say that E2 will involve a lot of "if" statements.
if(Button1==1)
{
Length=75
}
else {Length=0}
if(Button2==1)
{
Length=75
}
else {Length=0}
This is some simple code and yea thats all there is. Let me explain about "if" statements first. They are basically all about true and false.
<Noob>"1=tru 0=false rite?" One Noob, very One
<Noob>"bazturd"
What the noob has mentioned is correct. So basically:
if(1)
{
Length=75
}
Will ALWAYS make Length=75 its also the same as
Length=75
by itself, same for the inverse.
if(0)
{
Length=75
}
will never make Length=75 and is just a waste of space. This is where the buttons come in, they send a 1 if its pushed and 0 if its not. So replace the 1 and 0 of both cases with the variable Button1.
if(Button1==1)
{
Length=75
}
else {Length=0}
This basically means, If "Button1" is equal to one, make Length 75 , if it is not equal to one, make Length zero.
<Noob>"hao cum ther r = and sum ==" Well == is a comparing thing used in ifstatements basically it asks if the the first thing is equal to the second, if it is it returns True, which lets the if statement run Length=75. This puts the number into the variable "Length" and is a command, so you can't do:
if(Button1=1)
{
Length==75
}
Now what if the "Button1" is not pressed? It sends a zero into the E2 and to the if statement. thats where the else comes in.
if(Button1==1)
{
Length=75
}
else {Length=0}
If "Button1" isn't equal to 1 the if statement will skip Length=75 and go to the else and run the command in there instead. Making Length=0 hence making the door CLOSED instead of OPEN. There is also the use of elseif in which it doesn't run a command but runs another if statement instead.
if(Button1==1)
{
Length=75
}
elseif(Button1==0)
{
Length=0
}
But because we know if "Button1" is not equal to one it has to be zero making the above code more tedious even though it does the same thing.
The E2 will end up looking like this:
@name Door
@inputs Button1 Button2
@outputs Length
#@persist
@trigger all
if(Button1==1)
{
Length=75
}
else {Length=0}
if(Button2==1)
{
Length=75
}
else {Length=0}
To sum all of this up, basically the E2 accepts 2 inputs from two buttons, if Button1 or Button2 is pushed, the E2 outputs to the length of the hydralics and the hydralics will grow longer and OPEN the door. If the buttons aren't being pushed the E2 will output to the length of the hydralic a zero which will shorten the hydralics all the way which CLOSES the door.
Next time I will explain more about triggers, persists, and different comparing statements.
<Noob> gained 50 EXP points
<Noob>"res cum bak quikly plox" Don't worry I will. Off to GMOD!
7 days later...
<Noob>"yay u haf com bak"
Yes I have.
*ahem* onwards to (drumroll plz)
*tada*
Section 2
Anyways now that you know about E2 more and how to use if statements the rest should be quite easy now cause it is just some different comparing statements.
I shall now continue with the E2 from above. Now that I look at it (7 days ago), it is quite long and CAN BE SHORTENED.
Let us review this again, if either Button1 OR Button2 the E2 makes Length=75, if not then it makes Length=0.
So this is what we do:
if(Button1==1 | Button2==1)
{
Length=75
}
else{Length=0}
So what your thinking now is what that--
<Noob>"ROFL watts wif dat ell?"
.....
Yes, thank you SO MUCH for pointing that out.
<Noob>"ur welcm"
That "ell" or "|" is actually the statement OR and it is not an "ell" but a key that
sits above the Enter it shares it with the "\"
<--'
Basically if the "|" does not have a "\" on the key, wrong one!
So what we just did was about chop in half out coding but keep what it did.
Once again this means "If either Button1 or Button2 is pressed make the Length=75, if they are not pressed make Length=0"
Easy right?
Now let's say that we want the door to open when both the Button1 AND Button2 are pressed.
So ONLY if BOTH the buttons are pressed Length=75,
if only one or no button is pressed then Length=0.
The statement for AND is "&". This time I want you to write out that by yourself.
(P.S It is just like the earlier one)
<Noob>"WTFBBQ wut wif tat a--" *smack*
Anyways, this is the general idea of E2 if statements. Let us move on to persists and triggers.
Persists are self-explanatory, basically instead of input or output variables, they just stick around. If it was like this:
@name Door
@inputs Button1 Button2
@outputs Length
@persist Num
@trigger all
if(Button1==1 | Button2==1)
{
Length=75
Num++
}
else{Length=0}
Num would keep on adding 1 to itself as long as a button is pressed. Num will also keep the value until you destroy/undo the E2.
Somethings to note:
Num++ is the same as Num=Num+1 and Num+=1
Whenever you want to put something into a variable (in this case Num) it needs to be on the left side of the equal, so
Num+1=Num
won't work.
Also all persist variables START out EMPTY Num had a 0 inside from the moment that E2 was spawned.