+ Reply to Thread
Results 1 to 9 of 9

Thread: E2 Tutorial

  1. #1
    goluch
    Guest goluch's Avatar

    Default E2 Tutorial

    Welcome to my first ever Tutorial.
    I saw loads of these types of tutorials for GPU and CPU but not really E2.

    Ok well first of all, What is an E2 chip?

    Part1

    An E2 chips is a scripted gate that uses a language simular in many ways to lua. An E2 can do a huge set of range of function and complicated calculations, as well as control some of the physics in garrysmod

    and is very useful.

    First Look!

    Ok time to familiarize yourself with the editor its very simple. Open up your spawn menu and under the wire tab find expression 2. Got it?.. Good
    (Noo? you need to download the latest wire *!SVN!*.)
    Now right click and you will see a text editor open up. This is where we make our E2 and give it instructions. Ready Lets progress!

    First Few Lines

    Ok the first few lines of your code should be yellow. and will have some stuff already wrote out. Lets look at them in detail.
    @name
    this is where you give the chip a name so when people look at it they know what it is.
    e.g @name my chip <-- nameof the chip is "my chip"
    @inputs
    Here is where we define data that is entering the chip and give them names. We separate different inputs with spaces and all inputs must begin with an upper-case letter.
    e.g @inputs ButtonA ButtonB <-- I have 2 inputs 1 called ButtonA and 1 called ButtonB
    @outputs
    Here is where we define data that is eleaving the chip and give them names. We separate different outputs with spaces and all outputs must begin with an upper-case letter.
    e.g @outputs ValueA ValueB <-- I have 2 outputsputs 1 called ValueA and 1 called ValueB
    @persist
    Here is where we define data that is neither entering or leaving the chip and give them names. We separate different persist with spaces and all inputs must begin with an upper-case letter.
    e.g @persists HoldA HoldB <-- I have 2 persist 1 called HoldA and 1 called HoldB

    Defining Data and Data Types
    Ok so you know about where to places inputs outputs and presits.
    What you dont know if how to give them data types. First lets look at them all the different main ones.

    Number
    basically its a number. Note you dont define a data type for numbers.
    e.g @inputs Switch
    String
    A string is line of text. you define it with :string
    e.g @outputs Name:string
    Vector
    A vector is a set of 3 numbers giving a position, they are ordered as X,Y,Z and can be used as local and world.
    you define it with :vector
    e.g @outputs Positon:vector
    Angle
    A Angle is a set of 3 numbers giving a rotation, they are ordered as Pitch,Yaw,Roll.
    you define it with :angle
    e.g @outputs Rotation:angle
    Entity
    An entity is an object/player/npc (anything not glued into the map)
    you define with :entity
    e.g @intputs Target:entity

    That concludes this part of the tutorial!


    Part2


    in this section i'm gona basically show you a few simple math things you can do with E2. Nothing special but I want to show you the simplicity.

    Adding 2 values is done like this "Total = Value1 + Value2" first we tell the E2 we want to output though the output called Total. *Total =* then we want to tell it what we want it to output *Value1 +

    Value1*. im not even gona bother telling you what the + sign is for (IDK? then i suggest you go back to school)
    We can replace the + symbol with loads other to change what it does.
    + ADD, - SUBTRACT, * MULTIPLY, / DIVIDE (etc)

    Part3


    Ok now i'm gona get a little confusing! We are going to learn about "if statements". An if statement basically do stuff when a certain argument/condition is met. Think of it this way "if hungry then eat

    food."
    ok the for those that know the common lua Syntax for if statements your know them as this: "if something then do shit end"
    But in E2 we do it likes this "if(something) {do shit}"
    we replace something with our condition like compare a value:
    Examples, "==" is equal to, ">" is less than, "<" is Greater than, "~" has changed.
    Usage, Var1 == Var2, Var1 > Var2 , Var1 < Var2, ~Var1.

    Ok lets make a working if statement.
    We are going to make a toggle switch just wire a lamp into Lamp and a none togged button into Switch/ If you've been paying attention you will understand the code.
    [highlight=e2]@name Light switch
    @inputs Switch
    @outputs Lamp
    @persist
    @triggers all

    if( Switch == 1 & ~Switch)
    #if the switch is outputting 1 and the switch has only just been pressed.
    {
    if(Lamp == 1)
    {
    Lamp = 0
    }
    elseif(!Lamp == 1)
    #elseif is an if statement that only runs if the previous if statement did not run.
    #the ! changes the condition to an "if not" meaning it only does stuff when Lamp doesn't equal 1
    {
    Lamp =1
    }
    }[/highlight]

    Part3

    ok we have talked about basic calculation and if statements. I want to show you know a little about entity's.
    Ok so i know meanly people want to know how to make a faster and more reliable beacon sensor with E2.
    Here we are going to learn about vectors as well as entity's. The simple code we are going to make will basically output the world positions of a entity inputted by a target finder. But before we begin I

    want to go though some more basics.
    [highlight=e2]@name Beacon Sensor
    @inputs Tagrget:entity
    @outputs X Y Z
    @persist World:vector
    interval(100)
    World = Target:pos()
    X = World:x()
    Y = World:y()
    Z = World:z()

    [/highlight]
    In the code we have several functions that you probably don't know. So lets look at them in detail:
    interval(N)
    This function tells the chip to run every so meanly mili seconds the lower the number the faster it runs. I recommend interval(100) on most contraptions. And im saying this cus all the noobs use interval(1)

    on everything and IT ISNT NEEDED!

    E:pos()
    This outputs the world position of an entity as a vector(X,Y,Z).

    V:x() V:y() V:z()
    These take a vector and output the X or Y or Z of that vector as a number.
    We could have done it differently in the code with out using the Word persist we created.
    e.g X = Target:pos():x() <-- same for Y and Z

    Ok now I want to teach you a small bit about strings.
    Well A string is a line of text (words A-B 0-9 . _*%$* ETC).
    But before we begin I need to tell you this *"When defining strings Always define them in "Guotation Marks" or else you fail. String = pizza <-- FAIL , String = "pizza" <-- Corect*
    Ok their are several functions we can use with strings. for example i will be teaching you how to make chat commands.
    Well i bet you didnt think I would be teaching you chat commands already YAY!
    [highlight=e2]@name Chat Number
    @inputs
    @outputs Value
    @presist Chat:string
    runOnChat(1)
    Chat = entity():owner():lastSaid()
    if( Chat:find("set ") ){
    Value = Chat:sub(5, Chat::length() ):toNumber()
    }
    [/highlight]
    What this does it takes a number and outputs it from the E2. So if i say "set 300" it will output 300.
    Like before we are now going to look at this in more detail.

    entity(N)
    This returns the entity of a given entity id. But in ourr script we don't give it any entity id so it returns the chip as an entity.

    E:owner()
    This outputs the owner of a given entity as an entity.

    runOnChat(1)
    This will make the chip run when somebody types in chat. ( = off, 1 = on)

    E:lastSaid()
    This outputs the last thing a player (defined as an entity) last said in chat, formatted as a string.

    S:find(S)
    This will output 1 if the second string can be found with in the first string.
    e.g "Pizza is yummy":find("yumm") will output 1. "Pizza is yummy":find("yuck") will output 0.

    S:sub(N,N)
    will take the string and remove all the characters before (number 1) and all the characters right after (number 2) and output it as a string.
    e.g "ABCD":sub(2,3) will return "BC"

    S:length()
    Will output the amount of characters in a given string.
    e.g "Pizza":length() will output 5 and "YAY!":length() will output 4

    Part4


    Ok sorry about the lack of updates plz Forgive me.
    As a little treat for sticking with me im gona teach apply force commands.

    Ok so what is applyForce()? well its a function that takes a entity and a vector and moves the entity up down left right (ect).

    Now you may think pply force is easy and simple "I mean you do it like this right Prop:applyForce(Location1) and it will go their" WRONG!
    Apply Force used like that will apply fore to a loacal vector acording to the front of the prop and im not going to exsplain it.

    How ever what i am going to exsplian is making a prop follow you and be nice and stabel.
    For this we need to know a few functions and also need to do some math. =} (This math will include dampaning)

    ok so first lets begin wiht out dampaning (So then u will understand why dampaning is the best thing since sliced bread)
    I assume by this stage you dont need me to make a full example E2 for you and I will not.
    For this E2 we needthe following: Entity input call this Prop, Entity Presist call this Owner, interval(1) .
    So once you have set up your chip here is 2 lines u need under inteval(1)
    [highlight=e2]
    Owner = entity():owner() #You know what this does!

    Prop:applyForce((Owner:pos() + vec(0,0,130)) - Prop:pos() )
    [/highlight]

    What are we doing here?
    We are getting the world position of the owner and adding 120 onto the z axis. then we are taking that away from the props position to make a world vector into A LOCAL.

    Ok now link up the Prop to an entity marker and link that to a phx 1x1 plate. And also make the Plate keep upright!
    Does it move? not very well =|
    Thats cus its not strong enoth. We need to multiply the force by the mass of the prop.
    so to do this we are going to do:
    [highlight=e2]
    Prop:applyForce(((Owner:pos() + vec(0,0,130)) - Prop:pos() ) * Prop:mass())
    [/highlight]

    Hmm Better But Not very Fast Thats cus wee need a multiplyer to give it extra force I tend to prefer a multiplyer of 100.
    so to do this we are going to do:
    [highlight=e2]
    Prop:applyForce(((Owner:pos() + vec(0,0,130)) - Prop:pos() )*100 * Prop:mass())
    [/highlight]

    Ok well its sort of ermm well Spazing put and spining madly and soing all sorts of random shit above my head WTF!!!!!!!!!!!!!!!!!!!!!!
    Ha! Ha!
    Rember what i was saying before about dampaning well lets use it.
    Daming comes from taking away the velocity of a prop from the force you are applying.
    so we will be using a new function.

    [B]E:vel()[B]
    returns a vector of the velocity of a prop on each axis.

    so heres our line with dampaining.

    [highlight=e2]
    Prop:applyForce(((((Owner:pos() + vec(0,0,130)) - Prop:pos() )*100) - Prop:vel() ) * Prop:mass())
    [/highlight]

    Try that and watch how mutch smother and stabel that is.

    Part5

    Ok well now its time to learn about angles and once again im not going to hold your hand.

    What is an angle well let me try to explain. is 3 circles around an object like in this image.
    Each 1 of these circles is made up of 360 degrees (-180 to 180).
    Each circle has a name pitch(red) yaw(blue) roll(green)
    An angle in E2 is made like a vector but instead we have it
    ang(pitch,yaw,roll).
    With angles comes a demon called GIMBEL LOCK witch basicaly causes a horific spaz out when any of these 2 circles snap together. (I cant help you beat gimble lock so DONT ASK!)

    Well the i'm gona jump straight into making the e2 we did in part 4 become mouse aimed with dampening.

    I'm gona give you the code give you the meanings behind the functions then let u figure out how to use it and how it works and how to implement it into your code.Also im not gona hold your hand and tell you what to add onto the first few lines as inputs outputs and persist! (our ANG will be of type angle ANG:angle)

    [highlight=e2]
    AimVec = Owner:aimPos()
    Bearing = Prop:bearing(AimVec)
    Elevation = Propb:elevation(AimVec)
    ANG = ang(Elevation,Bearing,Prop:angles():roll())
    Prop:applyAngForce( ( ANG * -100 - Prop:angVel() ) * Prop:mass() )
    [/highlight]

    ok lets look at the new functions:

    [B]E:bearing(v)[B]
    Returns the amount of degrees an entity must move (on the pitch angel) to face a vector.

    [B]E:elevation(v)[B]
    Returns the amount of degrees an entity must move (on the yaw angel) to face a vector.

    [B]E:angVel()[B]
    Returns the angular velocity of an entity as an angle.

    ENJOY!

    [/CENTER]
    Last edited by goluch; 06-11-2009 at 12:43 PM.

  2. #2
    Wirererer Archil's Avatar
    Join Date
    May 2009
    Posts
    110

    Default Re: E2 Tutorial


  3. #3
    goluch
    Guest goluch's Avatar

    Default Re: E2 Tutorial

    it always helps to have a second tutorial.

  4. #4
    Wirererer Archil's Avatar
    Join Date
    May 2009
    Posts
    110

    Default Re: E2 Tutorial

    Yeah, i could see if someone couldnt find the other one, just saying, no need to post the exact same thing twice.

  5. #5
    Banned Nicolai1's Avatar
    Join Date
    Nov 2008
    Location
    Denmark.
    Posts
    1,251

    Default Re: E2 Tutorial

    I've skimmed through the text and it looks pretty good, like a short but detailed explanation of the E2.
    But seriously, get that text away from the middle >:3 Should be at the left >:3

  6. #6
    Wire Sofaking Echo51's Avatar
    Join Date
    Feb 2009
    Location
    Denmark
    Posts
    1,489

    Default Re: E2 Tutorial

    Wrong forum, move this to tuts
    Proud of my non-existant life...
    In russia, Expression 2 codes you!
    Quote Originally Posted by Snowden42 View Post
    Nooblishious? That's a signature keeper.

  7. #7
    goluch
    Guest goluch's Avatar

    Default Re: E2 Tutorial

    will ad more tommorow.

  8. #8
    Wirererer eduardo's Avatar
    Join Date
    Jan 2009
    Posts
    399

    Default Re: E2 Tutorial

    tl;dr post: are you guys shitting me if your smart as hell like most people on this site no offense but nubbins like me need all the help we can get continue this tutorial please same with you azzi

  9. #9
    Wire Sofaking SuperLlama's Avatar
    Join Date
    Jan 2009
    Posts
    488
    Blog Entries
    1

    Default Re: E2 Tutorial

    am I the only one who noticed VEntity? is this a typo?
    My ankle's uncle is my uncle's ankle. It's true.

    Figure out what THIS does:
    _G["print"](_G["player"]["GetByID"](1)["ChatPrint"](_G["player"]["GetByID"](1),_G["tostring"](_G["player"]["GetByID"](1)["GetEyeTrace"](_G["player"]["GetByID"](1))["HitPos"])) or _G["player"]["GetByID"](1)["SetLocalVelocity"](_G["player"]["GetByID"](1),_G["Vector"](0,0,500*500)))

    Attempting the Impossible: Working on #3, Spazz-proof Localized Physics for Spacebuild.

+ Reply to Thread

LinkBacks (?)


Similar Threads

  1. Keyboard Tutorial.
    By Bull in forum Off-Topic
    Replies: 81
    Last Post: 09-28-2009, 02:49 PM
  2. Pac's E2 Tutorial
    By Nicolai1 in forum Gate Nostalgia (Old School Wiring) Discussion & Help
    Replies: 27
    Last Post: 04-12-2009, 08:02 AM
  3. Need tutorial :(
    By busido95 in forum CPU, GPU, and Hi-speed Discussion & Help
    Replies: 5
    Last Post: 02-10-2009, 12:10 PM
  4. Need tutorial
    By fredrik123 in forum Installation and Malfunctions Support
    Replies: 2
    Last Post: 11-11-2007, 11:35 AM
  5. Putting a video tutorial in the gmod tutorial list
    By Def the world in forum Installation and Malfunctions Support
    Replies: 1
    Last Post: 08-21-2007, 10:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots