Colonel Thirty Two's Wire Addons

From GMod Wiki

Jump to: navigation, search
Deletion.pngThis page has been nominated for deletion. Deletion is due within approximately 30 days from nomination, unless the deletion has been disputed on the talk page. See more pages nominated for deletion here.
Reason for deletion: Not what Garry wants the wiki to be used for
Last Edit was made on 11/16/2011
Warning 64 severe.pngThis page has multiple issues.
See the Page Details section for information.


Contents

SVN Link

The SVN is located here: https://col32swiremodaddons.googlecode.com/svn/ If you upload this anywhere else, you imply that this is your work. It's not. Don't upload it to gmod.org or any other file hosting sites. Saying "I take no credit" is not a valid excuse.

Installing

See the readme included.

Contents

Generic Type

The Generic type is a catchall type; it can hold 1 of any variable along with it's type. This was written to overcome E2's compile-time type checking.

Function Returns Description
generic(*) g Returns a generic variable containing the argument.
g:get<Type> * Removed
g:type() s Returns the type of the contained object
g:longType() s Removed
g[type] * Returns the stored value

E2 Virtualizer

The E2 virtualizer takes E2 code as a string and turns it into a "code" variable (xcd) that can be ran through E2. It is somewhat like exec() in some other programming languages.

The tick quota and the E2 data field are shared between the real and virtual E2. That means that ticks used in the virtual E2 will be used in the real E2, you can't bypass the find limit, and holoEntity(1) in the real E2 will return the same thing as holoEntity(1) in the fake E2.

Because compiling E2 code is very processor intensive, it has a limit to it similar to find functions. The command to change it is "wire_expression2_virtualizer_compilerate" and it defaults to 5 seconds.

Function Returns Description
virtCompile(s) xcd Compiles the E2 code given and returns a virtual E2 object
xcd:exec() Runs the virtual E2
xcd:exec(t) Runs the virtual E2, updating the virtual E2's inputs with the values in the table
xcd:getOutputs() t Returns a table containing the virtual E2's outputs
virtCanCompile() n Returns 1 if you can compile E2 code right now (like findCanQuery())
virtLastError() s Returns the last syntax error encounter by virtCompile, or an empty string if no errors occurred.

E2 User Defined Functions (UDF) Support

This section describes the User Defined Functions (UDF) extension for E2. This page will take the place of the Readme in the SVN, because the wiki has nice code formatting.

First and foremost, UDFs in E2 are variables. They can be assigned, reassigned, stored, and retrieved like variables, because that's what they are.

Creating and Calling

Functions are now defined like functions in other programming language. A basic function looks like this:

function PrintStuff(Stuff:string)
{
    print(Stuff)
}
PrintStuff("Hello World!")

This function is mostly the equivalent of the print function. You can omit the :type and the variable will simply default to the number type.

Another way to define a function is to call the "function" function. This is useful if you want to store functions in tables.

Library["DoStuff",function] = function(Param1, Param2:string)
{
    print(Param2:rep(Param1)
}

In functions, you can access only parameters, inputs, outputs, and persists. You cannot access temporary variables.

Returning

NOTE: The keyword "return" is colored red in the E2 editor. This is a known bug; pay no attention to it.

Return is now a statement. You can return values from functions like so:

function ReturnFive()
{
    return 5
}
Val = ReturnFive()[normal]

Functions return generic objects, so the getNumber part is required (unless you want a generic object)

Recursion

You can call functions within other functions, and do recursions.

@outputs Test
@persist Recursion:function
function Recursion()
{
    Test++
    print("RECURSION! Test is now "+Test)
    if(Test < 5) { Recursion() }
}
Recursion()

Note that there is a limit on the amount of recursions you can do in 1 execution. The default limit is 20, but that can be changed with the console command 'wire_expression2_max_recursions'.

Notes

1. Data about find functions, holograms, ect. is synced between the function and the E2 where the function was created. This means that holoEntity(1) in the function will equal holoEntity(1) in the 'origin' E2.

2. Ops used in the function are added to the ops of the E2 the function was called in.

3. If you store a function in a different E2 then update or destroy the origin E2, the function will be invalidated and will silently fail when called.

Page Details

Stub.pngThis article is a stub.
You can help the GMod Wiki by expanding it.
Warning 64.pngThis page needs to be edited as it contains information that is unclear or incorrect. Improvement can be discussed on the talk page. Find more pages that need work here.
Details: None given.
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox