Go Back   Wiremod Forums > Wiremod Skills > Wiremod Tutorials

Wiremod Tutorials Post your wiremod tutorials/guides here.

Reply
 
LinkBack Thread Tools Display Modes
Old 10-21-2008   #1 (permalink)
<3

 
IEF015's Avatar
 

Join Date: Feb 2008
Location: London, ON (Canada, eh?)
Posts: 765
IEF015 has a spectacular aura aboutIEF015 has a spectacular aura about
Default Expression Gate 2 Language Tutorial

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
IEF015 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 10-21-2008   #2 (permalink)
Wire Guru
 
chinoto's Avatar
 

Join Date: Apr 2008
Posts: 420
chinoto is on a distinguished road
Default Re: Expression Gate 2 Language Tutorial

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..
chinoto is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-21-2008   #3 (permalink)
Member
 
SBII Gunz (AOD SD)'s Avatar
 

Join Date: Jun 2008
Posts: 55
SBII Gunz (AOD SD) is an unknown quantity at this point
Default Re: Expression Gate 2 Language Tutorial

This is easier to learn than E-Gate 1!

I am salivating over the possibilities.
SBII Gunz (AOD SD) is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2008   #4 (permalink)
Newbie
 
Legendary Ace's Avatar
 

Join Date: Jul 2008
Location: Washington
Posts: 26
Legendary Ace is on a distinguished road
Send a message via MSN to Legendary Ace
Default Re: Expression Gate 2 Language Tutorial

I liked it

Oh man, the endless possibilities with this, ENDLESS I SAY!
__________________
Legendary Ace is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-25-2008   #5 (permalink)
Wire Guru
 
Syranide's Avatar
 

Join Date: Mar 2007
Posts: 2,033
Syranide has disabled reputation
Default Re: Expression Gate 2 Language Tutorial

Very nice!

A few tips:

Code:
if(B3) {
    Screen = Screen * 10 + 3
}
Do it like this instead: (lots of duplicate lines, no complicated purpose, easier to see relationships in code if it doesn't add a lot of "empty" lines)
Code:
if(B3) { Screen = Screen * 10 + 3 }
And also, there is no need to have two separate setups for degree/radians, simply convert the output/input to/from degree/radians depending on the selection. (Could be done by simply having a conversion-variable multiplied to all those computations, then you set it depending on what has been chosen.
Syranide is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -7. The time now is 11:30 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.

Page top