User:Chinoto1/sandbox

This section is for example expressions. To make this section as useful as possible, please try to keep your examples simple and targeted to specific areas of Expression 2. For instance, a good example would show you how to make a basic GPS using Expression 2's vectors. This isn't a place for you to share your contraptions, you can do that here.

Guidelines:


 * When creating a new example make sure to follow the wiki format everyone else is using.
 * Put it in the correct complexity category.
 * Include (by [your name]) at the end of the title.
 * Include a description of what it does.
 * If you have more than one example that fits a difficulty, insert them one after another, it keeps things organized.
 * Use lua tags for your E2 code. The syntax highlighting isn't perfect, but it helps a lot with comments.
 * Coding
 * Please make sure the variable names you use describe what they are for, for example, use WeldLatch instead of WL for your variable name.
 * Follow the code format set in Expression 2: Formatting. Use 4 spaces for each indentation (comments are exempt).
 * Try to line up series of comments so they are easier to separate from the code.
 * This is a wiki, so expect your expressions to be modified by other editors.

RPM Counter (by Beer)
Description: Very simple expression for determining RPM using angVel. For this example, Wheel:entity is a PHX wheel linked to an Entity Marker. Depending on the prop you use, yaw may not be what you need. Try pitch and roll if you have trouble.

Code:

GPS (by Fishface60)
Description: This is a simple expression to get used to the new functionality, it would be suitable practice for a new user. The Interval is required for the GPS to update its values, as there are no inputs to change for it to recalculate. It will update ten times per second, if you need more or less you can change the interval.

Code:

Speedometer (by integer)
Description: This will output the speed of the chip in Knots. This is achieved by getting the entity's velocity, then getting its length, which in the case of velocity is the speed. After this it is converted to Knots, if you prefer to use a different unit then change the knots to the desired unit.

Code:

Detonator (by Syranide)
Description: After the button is pressed then the timer starts, making the output 1 after 1 second, then it resets itself after 100ms.

Code:

Chat example (by Matte)
Description: Simple expression showing how to set a value in the E2 via chat commands. It takes what the owner said, explodes it into an array, and checks if the first string equals "/light". If it does, it sets the Light-variable equal to the second variable. For instance, "/light 2" would set Light to 2.

Code:

Beacon Sensor (by Hitman271)
Description: A piece of simple code to show more entity interface. The TargetE input goes to the entity output of a target finder.

Code:

String Example (by Hitman271)
Description: Always remember to declare the variable type in the input and output fields when in doubt. Watch this code in the debugger. Tar would goto the entity output on a target finder.

Code:

String Explode (by Hitman271)
Description: Another simple code to show how to separate a string easily. This code prints to chat so no need for debugging

Code:

WireLink Example (by Hitman271)
Description: A wirelink example. The wirelink is located in the wire section of the wire menu, or right by the normal wire stool.

You will need; A target finder, A holo emitter, A holo grid, A constant value of 1, and this code of course. Right-click the emitter, then left-click the grid to connect them. On the grid's input of USEGPS, wire it to the constant value of 1.

With the wirelink stool, left-click the emitter.

Set the target finder to players or npcs.

Then wire the E2 Holo[WIRELINK] input to the emitter. Then the E2 Player[ENTITY] input to the target finder's entity output.

With the wirelink, MUCH less wiring is required as the emitter's input have been untouched to demonstrate.

Code:

Vector and Entity wirelink testing (by fishface60)
Description: These are the expressions I used to test whether the then new wirelink entity and vector functions were working, they serve as basic examples of how to use them.

WireLink[S,vector]

WireLink[S,vector] = V

WireLink[S,entity]

WireLink[S,entity] = E

Basic Player Targetting (by jman31415)
Description: Can target Players with chat by typing !target followed by the player's name.

Code:

Thanks I would like to give a huge amount of credit to Matte for his example and credit to Shoffing for introducing me to chat controlled functions.

Follower (by Chinoto)
Description: Follows an entity, orientation does not affect it.

Code:

Door (by Chinoto)
Description: This expression can accept 8 inputs for opening/closing a door ("If any variable is 1" then door opens/closes) and will automatically close after 10 seconds. If wanted you can also add a weld latch so then the door can't be opened through brute force, just wire length to the hydraulic controller and the weld latch to the expression.

Code:

Table-RAM (by Magos Mechanicus)
Description: An example of the use of tables, this expression saves and outputs number data based on input in much the same way a RAM chip does. You control what data to save or retrieve with AddrRead and AddrWrite, and cause it to save the input Data in the address AddrWrite with the (edge-triggered) Clk input. Note that unlike an ordinary RAM chip, you are not restricted to any particular number range for addressing, though the table will take up a lot of memory with many values saved.

(Syranide: I'd just like to point out that this method is fine, but it should not be used for as a proper memory because every single number will consume a large amount of space, more than 10 bytes each. So do not use it if you will be saving alot of data.)

Code:

Array-RAM (By GUN)
Description: Array are new to e2 and are made to be used as internal ram, its basically EXATLY the same as table ram, but its much more easy to code and use

Code:

See, its basically the same as table ram. Except that you don't have to transfer it to a string to write it to the ram. But on the other hand, you can also use arrays to store vectors or strings as well. But be aware, no matter which you use, you're limited to 1048576 cells or 1 MB(THAT'S A LOT!!). You will most likely NEVER use anything close to that. And with arrays you can also Reset the entire "ram" or array with the Ram=array:clonefunction, so that's a new thing :P have fun :) -GUN

Gyroscope (by GabbaGubbel)
Description: Its just to take the Expression2 like a Gyroscope.

Code:

New syntax (By Divran)
Description: These two E2s communicate using the 'new' system.

Code:

Old syntax (By ZeikJT)
Description: Example code using two expression2 chips to communicate wirelessly using a custom groupset.

Code:

Using Built-In Ranger (by ZeikJT)
Description: Example code using and expression2 chip to do ranger calculations.

Code:

Built in ranger and wire colorer example (???)
Description: Using expression 2 to color an object between a built in ranger just like the wire colorer. It also resets the entities color when its not between the built in ranger.

Code:

Using Hints (by hurricaaane)
Description: hint(S,N) is a simple way to display strings onto your screen, including for debugging pruposes. It will appear like messages "Undone Wire Gate" appear. You can also spawn a notice popup when the expression is spawned using if (first).

Usages in a vehicle could be to display a notice to the passengers about the usage of the vehicle.

Code:

Holo Emitters (by Entoros)
Description: These are two expressions that both do something with holoemitters; the first creates a sphere, the second follows you around in a cool helix.

Code:

Chip Buddy (by Marshmellow)
Description: This is simply a chip that floats above your head and follows you around. All you have to do is spawn it and click on it with your physgun to make it work. I made it for those of you who are trying to learn vector basics. E-mail me at justizzle550@gmail.com if you have any questions.

Code:

Find player by steamID or partial steamID (by Venompapa)
Description: Use "for" loop function to find players by full or partial steamID.

Code:

Checking a material on a prop (by Godd)
Description: A code that allows you to check the material of a prop by placing the e2 on the prop

Code:

Counter Example (by Slaiiz)
Description: This is a not-so-hard-to-understand code that shows how to make a switcher using any triggerable thing.

Code:

Player targeting via Chat (by Wodden)
Description: With this handy little expression you can target players, by typing !target followed by the name.

Code:

Advanced Player Targetting (by Jackorobot)
Description: This is an code that targets people easier then Wodden's Code. Usage: type in chat: "/target [name|partial name]"

Code:

Velocity Stabilisation (by fishface60)
Description: The purpose of this expression is to allow thrusters placed anywhere on a contraption to right the orientation. To make it work on your contraption you may need to reassign the forward, right and up vectors dependant on which way you like up. Also, some Values may need to be negated, and for it to run smoothly you may have to multiply by some constants. To use, create an entity marker and link it to the prop you want to use for the base, in my case a vehicle pod. Then spawn a vector thruster and use the wirelink tool on it to create the wirelink output. After this just wire it up. Remember that you need one of these gates per vector thruster, it doesn't have to be located near the thruster though, it can be closer to the control circuits to make it easier to wire, or it could be on a control board, which could be recommended to reduce lag.

Code:

Missile (by Exitium)
Description: As the name suggests, this is my homing missile expression. It needs the following:

- Vector thruster. - Thruster. - Target finder. - Button or some other input to fire it. - And a missile!

Simple to wire:

- Target Finders entity -> TargetE. - Target Finders 1 -> HasTarget. - Button or other input -> Fire.

- CoordsV -> Vector thrusters vector input. - Go -> Thrusters A and Vector thrusters Mul.

The other crap is for a multi stage, multi warhead missile that uses weld latches, but that parts still work in progress.

Code:

Gyroscopic Stabilization (by chinoto)
Description: Using force functions to make a expression resist movement and gravity, and align itself with ang(0,0,0).

Code:

Code: Because of complaints from Jimlad about it being hard to understand and getting people into the "bad" habit of using short variables, I made an alternate with longer variable names.

Force Circle (by chinoto)
Description: Uses force functions and a while loop to make a bunch of entities orbit.

Code:

Defy Gravity (by chinoto)
Description: Uses force functions and while loops to make a bunch of entities defy gravity and to a small extent, velocity.

Code:

Radar Chip (Ranger and Wirelink) (By Coder0xff)
Description: Use the ranger commands to feed a digital screen with depth perception. All you need is this code in a chip and a digital screen. Shoot the digital screen once with the "Expression 2 - wirelink" stool. Go to the wire stool, and connect the LCD input of the chip with the [wirelink] output on the monitor. Use the physics gun to move the chip around and watch the display update. Make sure you follow the short instruction at the end of the code to take that block of code and copy paste it so there are 16 copies, total. It'll update much faster that way.

Code:

Applying Entity Discovery: Thermometer (by Entoros)
Description: Uses Gwahir's Entity Discovery functions to create a thermometer of sorts. It detects whether entities near it are on fire, then changes the temperature accordingly.


 * Note: this code is not perfect, but it's a good example.

Code:

NPC pet (by Bobsymalone)
Description: This is a simple demonstration of the NPC control functions, being used to turn the nearest NPC into a pet. Wire a button or numpad input to Find and press it to find the nearest NPC.

Code:

Introduction to applyForce and applyAngForce (by Mr. Scruff)
Description: A really basic detailed introduction to applyForce and applyAngForce. This Expression 2 baisically makes whatever you spawn it on hover above your head and look where you look.

Code:

Apply Angle Force Turret (by Sax)
Description: It's pretty basic really, basically you wire the Vehicle:entity input to an entity marker that is linked to a pod and Activate is connected to whatever you want as "On". The turret has support for Camera controller.

Code: Angle Calcs rewritten by chinoto

Text controlled props (by Shoffing)
Description: This expression can control props in many different ways using player input from chat.

Download Link

Simply click here and copy-paste into an expression 2 gate to use it. "Text Controlled Props"

Made by shoffing; cleaned, organized, and perfected by Chinoto. Text controlled props is being continually worked on by both shoffing and chinoto, so check back to see if there are any updates.

Artillery (by Shoffing)
Description: This is meant to be a realistic sounding/feeling/looking artillery barrage. It uses soundPlay,applyForce,timers, and many more. Just put one on every prop you want to use (you need 1 per prop for the sounds), then say "/t [name]" (no brackets, not case sensitive) Then, when your ready, say "/fire" and all the props will fire at a random interval at a random point in a 250 unit radius of the targeted player. It's really cool, it shakes the ground too haha. If you're looking for effect, use this.

Code: Go here to get it!!! It was too big again :/ "Artillery"

Bone Example: Zombie (by Shoffing)
Description: This expression will turn any human-looking ragdoll into a zombie that follows you, arms outstretched. Go ahead and add your own sound effects, I just thought of doing that now. xD

Code:

Music Example (by Shoffing)
Description: Using lots of time and proportions, I was able to "convert" 2 octaves of the musical scale into soundPitch changes for the sound "synth/tri.wav" (which happened to be 440 frequency) Using these discoveries, I have created the love theme from Star Wars using timers, soundPitch, and soundPlay. Feel free to implement.

Code:

HINT: Creating a 2D array with 1D arrays using strings (by Shoffing)
Description: Lets say you wanted to make a chess board and needed something to save the position of the pieces into. You cant use just a normal array, right? Because you need 2 dimensions (x and y) to fill in the board. My way of getting around this is to use strings in all the slots of an array, and checking their indexes to get information from them. For example:

Code:

Remote Trail Maker (by OmicroN)
Description: I thought that it would be neat to make chip that would allow you to set trails to any entity that YOU OWN just by looking at it and pressing a button, enjoy

Code:

World Orientation (by coder0xff)
Description: Creates cones and a sphere to indicate the positive world axes. They grow and shrink based on the owners distance so that they always fill about the same space on screen.

Code:

Angular stabilization using applyTorque and quaternions (by Fizyk)
Description: Stabilizes an entity in an orientation given by an angle. If you want to make something facing a particular direction, get the direction as a vector V, use V:toAngle and proceed with this code.

Code:

Mass Prop Colorer (by RoflChoppa)
Description: This expression will turn all of your spawned props red as an example of "for loop" usage.

Code:

Hologram Clipping Example (by Soul less)
Description: An example of the new holoClip function, used to clip holograms.

Code:

Target Crusher (by I_am_Einstein, modified by Initrd.gz)
Description: A standalone Expression 2 Chip that crushes targets that the user designates through chat, in the format: "/crush "

Code:

WAN IP Fetcher (by Nitrousoxide)
Description: An Expression 2 chip that retrieves your WAN (Wide Area Network) IP Address and returns it in the form of a string or in separate octets (array and number form).

Code:

Using findRe & replaceRE (by OmicroN)
Description: http://www.wiremod.com/forum/wiremod-tutorials/17699-how-use-findre-replacere.html Visit the link to read about it, I'm putting the link here so people who read the wiki know about it as well.

Console Screen Selection Screen (by GlitchDetector (|SpB| FB GameMaker))
Description: A expression 2 code to make the famous selection screens on automatic gunshops.

Code:

E2 Gravity Enabled Hoverdrive (by ILOVEPIE)
Description: An expression 2 code to make a Hoverdrive Controller that does not mess up your contraption's physics.

Code: