• Goldstrum : Basic wire expression2 (e2) tutorial
    9 replies, posted
[b] Introduction [/b] Alright, so i've been seeing people lately not knowing how to do e2's and they are really easy, but today i just want to give people the basic footings for e2 so they can get started. :eng101: [b]Requirements [/b] :eng101: To do e2's you need Garrysmod (why did i say this? i really don't know but its out there now.) Wiremod (I really hope you have this, its what expression 2 comes from) A basic wiremod knowledge (Just basic knowledge of inputs and outputs) :eng101:[b] Lets begin [/b]:eng101: Ok so e2 isn't really hard, if you pay attention. Ok so to start you goto the chip section of wiremod and click on wire expression 2.The model used does not matter. Either click on a prop or the ground to make a e2 chip, or just click on the "new expression" button, if you've just made a chip then right click. Now a text editor should open, this is where all of the e2 magic happens. You should see a list of phrases that are similar or the same to the following. [code] [b] @Name @Inputs @Outputs @Triggers @Persists [/b] [/code] This is where you enter the initial info to configure the fundamentals for the e2. @Name : This is where you enter the name of your chip, it doesn't need to ever be anything specific. @Inputs : In laymans terms this is the initial entity that activates the resulting entity, i'll give an example later if you are confused. @Outputs : This is the resulting entity thats activated after the intial entity is activated. I hope this makes sense. [b] ( I won't be covering triggers and persists in this tutorial, they'll be for another time.) [/b] So as triggers and persists are not essential in your first e2's you can delete both of the lines for them in the editor. Make sure to have a e2 name entered and click save as, a name needs to be entered to save, but whatever you have entered in the editor as the name is auto filled in the text bar that you enter the name in. Now spawn the chip, if you havn't done anything wrong it will spawn without any issues, making errors in e2's oftenly cause it to not work and give nasty looking red errors. Now i will use an example to teach you about the inputs and outputs. Make a ranger and a turret, and some firm prop to place them on like a phx 1x1 or a blast door prop. The wire settings for the ranger and turret do not matter. So make them whatever you want. Now this is how the e2 works. The ranger is the Input entity and the turret is the Output entity. Think of it like this, once you run past the rangers detection it goes through the ranger and the ranger sais "oh, someone has walked past me, lets tell bob the turret." so the info goes from the ranger, to the turret that shoots, being the output (reaction) So in your e2 text editor your input and output lines will and should look like this. [code] [b] @Input Ranger1 @Output Turret1 [/b] [/code] The input in the input line MUST start with a capitalised letter and end with a number to identify it, because you can have more than one input and more than one output like so [code] [b] @Input Ranger1 @Output Turret1 Turret2 [/b] [/code] ------------ :eng101: [b] What have you learnt so far? [/b] :eng101: Are you still with me? i hope so, if you are then you have just learnt how to: .Use the wire expression2 chip .Basic terms and how to use the text editor .Making and inserting inputs and outputs. Next we are going to learn some simple code that tells the inputs and outputs what to do and when. :eng101: So, a line or two beneath @outputs, write "if" without the commas.If you've done this correctly then the word "if" should turn blue. The word "if" tells the script if one thing is true then do something, it links into lua and if you know lua then it all goes hand in hand.But its still not a problem if you don't know any lua. So after "if", make the rest of the line. [code] [b] if (Ranger1) {Turret1=1} else {Turret1=0} [/b] [/code] So let me break that line of code down for you. As said, the phrase "if" tells the script if something is true, or false then do something. in normal brackets then is the inputs. Remember to include a capital letter at the begining and a number to represent it at the end (make sure the number is the same) In curly brackets {} are the outputs, same grammar rules apply as the inputs but you have to have a =1 or =0 at the end this is saying that if the turret is activated then its 1, if its not then its 0. else means that if the input is not activated then resort to another output value which in this case is off. =0 So in english this is what that line is saying. If Ranger1 is activated then Turret1 is activated otherwise Turret1 is de-activated. That is all you need to know to make a basic e2 code. [b] Heres a full coded example [/b] This is what it should end up looking like. [code] [b] @Name Laser detection turret @Inputs Ranger1 @Outputs Turret1 if (Ranger1) {Turret1=1} else {Turret1=0} [/b] [/code] Now you just get out your wiring tool, advanced is your best choice. And then very basically wire Turret1 of the e2 to the turret and Ranger1 of the e2 to the ranger. [b] Please be aware that i wanted to get this out for you all as soon as possible, i'm currently trying to get some pictures so please be patient. [/b] [b] I'll also soon be uploading a youtube tutorial [/b] [b] If you have any questions, problems or in-game e2 errors and can't fix them by yourself then tell me either via this thread or via pm. [/b] [b] If this tutorial has helped then please let me know. [/b]
Nice tutorial. Now I got 200 posts! Yay!
Thanks. But if it helps i'd be writing it up myself
No problemo!
Inputs/ Outputs don't need to end with a number. Where did you get that bullshit? Sure it is useful if you name another Input the same thing, but it is not necessary.
Ah sorry, its the way i do it and yet it doesn't harm. I tend to name a ranger a ranger, a turret a turret etc etc.
The above is correct. It does NOT need to end with a number, but is useful if you plan on having many different inputs/outputs doing something similar. Also, you need to do more about structure. [code] if () {} if () {} else {} [/code] [code] if () { } if () { } else { } [/code] [code] if () {} else {} [/code] Explaining in this case, it ignores all spaces/newlines. As for the tutorial: [url]http://www.wiremod.com/forum/expression-tutorials/[/url]
Here's some tips on coding style (based on the way I code things) - When putting comments in your code, PLEASE make sure that there is a space between the comment character (in E2's case, #) and your comment. This makes it slightly easier to read. And I think it looks better, tbh. - INDENT. Make indentations (usually a tab character or a few spaces) within if-then-else blocks, for loops, what have you. You have NO IDEA how many times I've managed to forget where the hell I was in the hierarchy of someone else's code because they didn't indent sensibly. - One statement per line please. It's just good practice. - If you think a statement's going to be humongous (i.e. a long printColor()), break it up across multiple lines. Don't forget to indent this a bit too (to the func's beginning parenthesis is usually a good rule of thumb). There, humans can read your code!
Also, instead of: [code] if (One & Two & Three) { } [/code] Do: [code] if (One) { if (Two & Three) } [/code]
I gave a basic starter, but its nice to see everyone else giving contributions :smile:
Sorry, you need to Log In to post a reply to this thread.