|
| |||||||
| Wiremod Tutorials Post your wiremod tutorials/guides here. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| <3 ![]() ![]() Join Date: Feb 2008 Location: London, ON (Canada, eh?)
Posts: 765
![]() ![]() | Code: @name Calculator #This is your name. It can be anything you want.
#Basic inputs
@inputs Clk B1 B2 B3 B4 B5 B6 B7 B8 B9 B0 Ne Add Sub Mul Div Equal Clear #This is what will show up when you are ready to wire the whole chip.
#Extra Inputs
@inputs SetRAM ClrRAM RclRAM Pi Power Sin Cos Tan SETDegRad ClrError #These are more inputs. You can have multiple @name, @inputs, @outputs, and @persist
@outputs Screen DegRad Error #This is what the chip will output. Sending values from the expression to another chip.
@persist In1 In2 Op Ram #These are persist. These are used to Store values for later use. You use these if you don't want them to be used as inputs or outputs.
if (Clk) { #On/Off Switch. If this is on, the whole entire main body of the code will be set active. In EGATE 2, if statements must start with "if", unlike in EGATE 1. In EGATE 1, you used "->" to begin the functions of an "if" statement. In EGATE 2, you end with "{".
# _________________________________________________________________
#BEGIN CODE _________________________________________________________________
#NUMERAL BUTTONS --------------------------------------------
if(B1) { #If B1 (Button 1) is true... --Remember, Starts with "if", ends with "{"
Screen = Screen * 10 + 1 #Screen will multiply itself by 10, then add 1.
} #When you are finished with an "if" statement, you will end a "}", to break the "if" statement, to stop it from functioning any further. Like in the EGATE 1, you will use ";". In EGATE 2, you use a "}".
if(B2) { #If B2 (Button 2) is true...
Screen = Screen * 10 + 2 #Screen will multiply itself by 10, then add 2. It will continue for this section of the code.
}
if(B3) {
Screen = Screen * 10 + 3
}
if(B4) {
Screen = Screen * 10 + 4
}
if(B5) {
Screen = Screen * 10 + 5
}
if(B6) {
Screen = Screen * 10 + 6
}
if(B7) {
Screen = Screen * 10 + 7
}
if(B8) {
Screen = Screen * 10 + 8
}
if(B9) {
Screen = Screen * 10 + 9
}
if(B0) { #If B0 (Button 0) is true...
Screen = Screen * 10 #Screen will multiply itself by 10, to add an extra 0.
}
#BASIC CALCULATOR BUTTONS ------------------------------------
if(Ne) { #If Ne (Negation) is true...
Screen = -Screen #Screen will negate itself.
}
if(Clear) {
Op = 0 #Operator will go back to 0
Screen = 0 #Screen will go back to 0
In1 = 0 #Input 1 will go back to 0
In2 = 0 #Input 2 will go back to 0
Error = 0 #Error ID will go back to 0
}
if(ClrError) {
Error = 0 #Much like the Clear button, but it will only remove the error.
}
#OPERATORS --------------------------------------------------
if(Add) {
In1 = Screen #Input 2 will now change into the value of the Screen.
Screen = 0 #Then, the screen will change back to 0. This MUST be after "In2 = Screen" or it will turn the screen to 0, then change In2 into 0, which is what we don't want.
Op = 1 #Change the Operator ID to 1.
}
if(Sub) {
In1 = Screen
Screen = 0
Op = 2
}
if(Mul) {
In1 = Screen
Screen = 0
Op = 3
}
if(Div) {
In1 = Screen
Screen = 0
Op = 4
}
#WHEN EQUAL IS PRESSED --------------------------------------
if(Equal) { #When Equal is pressed or True...
In2 = Screen #In2 (Input 2) will change to the value of the Screen
if(Op==1) { #If the operator ID is equivalent (equal) to 1 (Look back to OPERATORS section), then...
Screen = In1 + In2 (Screen will equal In1 plus In2)
}
if(Op==2) {
Screen = In1 - In2
}
if(Op==3) {
Screen = In1 * In2
}
if(Op==4) {
Screen = In1 / In2
}
}
#MEMORY -----------------------------------------------------
if(SetRAM) { #If SetRAM is true...
Ram = Screen #Ram will change its value to what's on the screen.
}
if(ClrRAM) { #If ClearRAM is true...
Ram = 0 #Ram will change to 0, removing it's value completely. Ready for a new Value.
}
if(RclRAM) { #If RecallRAM is true...
Screen = Ram #Recall (Hence the name :D ) the ram back to the screen. So, Screen will display what's in the Ram.
}
#TRIGONOMETRY -----------------------------------------------
if(!SETDegRad) { #If SETDegreesRadians is NOT true... (The "!" will set the value to false)
DegRad = 1
}else{ #This is an Else statement. It will function in the opposite of your last "if" statement ( "if(!SETDegRad) {", ). Therefore, it will function "If SETDegreesRadians IS true..."
DegRad = 2
}
if(DegRad == 1) {
if(Sin) {
Screen = sin(Screen) #Screen will equal Sine of Screen.
}
if(Cos) {
Screen = cos(Screen) #Screen will equal Cosine of Screen.
}
if(Tan) {
Screen = tan(Screen) #Screen will equal Tangent of Screen.
}
}
if(DegRad == 2) {
if(Sin) {
Screen = sinr(Screen) #Screen will equal Radians Sine of Screen.
}
if(Cos) {
Screen = cosr(Screen) #Screen will equal Radians Cosine of Screen.
}
if(Tan) {
Screen = tanr(Screen) #Screen will equal Radians Tangent of Screen.
}
}
#DEBUG ------------------------------------------------------
if(Equal & Op == 4 & In2 == 0) { #Divided by 0
Screen = 36606
Error = 1
}else if(Screen > 99999999) { #Too many digits
Screen = 36606
Error = 2
}
# ________________________________________________________________
#END OF CODE ________________________________________________________________
}else{ #End On/Off Switch. When the Clk is turned off, the whole gate will stop functioning the main body.
Screen = 0 #This will change the screen to 0, making it so it feels like the gate is outputting nothing. If this wasn't here, the screen will stay at whatever number it was last. Unable to change until the EGATE 2 is turned back on.
}
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- It's a calculator with many functions. All the comments will show you how most lines work. I know, I know, it's not really a tutorial. It's more of an explanitory code. It's good if your moving from Egate 1 to Egate 2 and don't know the syntax very well.
__________________ Signature: WIREMOD WILL NOT WORK ON A PIRATED GMOD! ![]() ![]() MY COLOUR IS BLUE. Post your expressions here: www.wiredexpressions.tk It's my favourite country song. And I hate it. IEF015's got his own website :3 |
| | |
| Sponsored Links | |
| | #2 (permalink) |
| Wire Guru ![]() Join Date: Apr 2008
Posts: 420
![]() | Good tut, I didn't know that more inputs could be made by just making a new input line. If you added some more functionality you could enter this expression into the calculator contest [Extremely Hard] Wired Calculator and you could also put a link to this page on the egate2 wiki/documentation http://wiki.garrysmod.com/wiki/?title=Wire_Expression2
__________________ ![]() (\__/) Wiremod Chinoto's Tutorials and Tutoring (Go here for "in-person" tutoring) (='.'=) ABX Chinoto's Wire Tutorials (Text tutorials so far) (")_(")<- Put this bunny in your sig and help him to rule the world. (My first internet infection) Last edited by chinoto; 10-21-2008 at 10:17 PM.. |
| | |
| | #5 (permalink) |
| Wire Guru ![]() Join Date: Mar 2007
Posts: 2,033
![]() | Very nice! A few tips: Code: if(B3) {
Screen = Screen * 10 + 3
}
Code: if(B3) { Screen = Screen * 10 + 3 }
|
| | |
| Sponsored Links | |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|