E2 Colour Changer

From GMod Wiki

Jump to: navigation, search

A Prop Colour Changer, compete with preview.

In this tutorial I'll be teaching you how to make an expression 2 chip that allows you to colour props, and it will preview your desired colour settings on a wired light. I recommend viewing my previous tutorial E2_Counter as this will help you greatly with this tutorial as it uses the same concept in an extended format.




Introduction -

What this contraption does is extend on my previous tutorial E2_Counter using the skills gained we will apply them to this more complex, but still just as easy expression 2. Once complete on a 2x2 PHX plate will be a wire light, 7 buttons and 3 screens. On a 1x1 PHX plate will be a wire colorer. You will then select the desired colour which will preview on the wire light, then you move your prop into the colourer's beam and then press the fire button to colour it.
The Expression 2 Code

@name Light Setting
@inputs Redadd Redsub Greenadd Greensub Blueadd Bluesub Fire
@outputs Red Green Blue Fireout
@persist
if(Redadd == 1 & Red >= 0 & Red <255)
{
  Red+= 5
}
if(Redsub == 1 & Red > 0 & Red <=255)
{
  Red-= 5 
}
if(Greenadd == 1 & Green >= 0 & Green <255)
{
  Green+= 5
}
if(Greensub == 1 & Green > 0 & Green <=255)
{
  Green-= 5
}
if(Blueadd == 1 & Blue >= 0 & Blue <255)
{
  Blue+= 5
}
if(Bluesub == 1 & Blue > 0 & Blue <=255)
{
  Blue-= 5
}
Fireout=(Fire ? 1 : 0)


What the code means



The first line of code defines the Expression 2 chips name. This can be anything you want but if you plan to use them on public servers give them a meaningful name!

Line 2 Defines the Chips inputs ; In this case I've defined sevon inputs, "Redadd Redsub Greenadd Greensub Blueadd Bluesub Fire" Each colour has an Add and Sub input which adds 5 or subtracts 5 for that colours count. the fire input is for the button which triggers the wire colourer.

Line 3 Defines ouptuts ; In this case "Red Green Blue Fireout", the Red Green and Blue are wired to the light, the individual wire screen for that colour and the colourer, and the fire output goes to fire of the wire colourer. Pretty self explanatory.

Line 4 Defines persists ; Persists are basically internal inputs and outputs that are not wired up, for the purposes of this we don't need any, so don't worry about them.

The previous 4 lines are required in every expression, otherwise you get error messages. The next lines are the actual unique code for your expression.

Line 5 and 6 at a glance look almost the same but there are three key differences I will explain in greater detail ; Line 5 basically takes the input of the Redadd button and checks to see if the value of the Red is greater than or equal to 0, and less than 255, if it is it will add 5 to the count. Line 6 takes the input of the redsub button and checks to see if the count is greater than 0 and less than or equal to 255, if it is it will subtract 5 from the count. Lines 7,8,9,10 are the same but they are for the other two colours.

In line 11 we are defining the value of fireout, if fire is 1, then output 1, otherwise output 0. This controls the wire colourer, if the output is 1, the colourer will output the RGB values, if not it won't. Simple.

Wiring instructions


The Finsihed Counter!
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox