LUA Box

Health
 Armour Class
 Structural
 Weight
 Relative Buoyancy
 Size
 Material Cost | 90

Please help improve this if you can. The Discussion page may contain suggestions.

**This article may need updating to the game's current version. Use information provided here with care.**
Please help improve this if you can. The Discussion page may contain suggestions.

## Mechanics

If a LUA Box is destroyed, execution is suspended until it is repaired. The box will keep its previous state.

Lua code is stopped when the vehicle is pulled out of play. The code is restarted anew when a vehicle is put into play.

## Basic Tutorial of From the Depths Lua

The interface may seem confusing and un-intuitive at first, but after a bit of practice, you will be able to create large scripts in order to accomplish various things.

### Glossary of Technical Terms

#### Values:

##### Variable

* Something that can be changed, or can be thought of as somewhere were one can store values

##### Integer

* A value that is any whole number, from negative infinity to positive infinity.

##### Float

* A value that is a floating point number, or a decimal.

##### Bool

* Short for Boolean. Simply stores a value as true or false.

#### Logical Operators and Loops:

##### For loop

* A form of loop that allows one to easily iterate through the contents of a array or or do things a certain amount of times.

##### While loop

* A form of loop that repeats a set of statements while a certain condition is met

##### Logical Operator

* In Lua, logical operators are not limited to boolean values, instead, they consider anything that is either false or nil as false, and anything else as true

##### Not

* A logical operator that takes in a singular value, and if it is equivalent to false, it will return true, and if it is equivalent to true, it will return false.

**-WARNING. BECAUSE LUA LOGICAL OPERATORS ACCEPT NON-BOOLEAN VALUES, THEY (OTHER THAN NOT) BEHAVE SLIGHTLY DIFFERENTLY TO OTHER PROGRAMMING LANGUAGES, SO BE SURE TO READ WHAT'S AHEAD-**

##### Or

* A logical operator that takes in two values, and returns its ***first input*** when said input is equivalent to true, and its ***second input*** otherwise.

##### And

* A logical operator that takes in two values, and returns its ***first input*** if said input is equivalent to false, and its ***second input*** otherwise.

## Functions

### Logging/Debugging

#### I:Log(Message)

* Takes in a string for a log and writes it to the log. These logs will be shown in the "Errors/Logs" panel within the Lua Box. The last 100 of these messages will be maintained.
	+ Useful for debugging algorithms by printing out values, execution errors, etc.

#### I:LogToHud(Message)

* Takes in a string message and displays said message as a pop up on the user's HUD, no matter where they are.

### Fleet Awareness

#### I.FleetIndex

* the read only integer that describes the position of the ship in the fleet, starting from zero.

#### I.isFlagship

* the read only boolean that tells Lua whether the ship is the flagship of its fleet or not.

#### Fleetinfo

* ID
	+ Integer ID of the fleet.
* Name
	+ String name of the fleet.
* Flagship
	+ FriendlyInfo object of the flagship.
* Members
	+ FriendlyInfo object array that consists of the ships within a fleet.

### Resources

#### I.ResourceZones

* An array of ResourceZoneInfo objects that lists all of the resource zones.

#### I.Resources

* A ResourceInfo object that describes a vehicle's available resources.

#### ResourceZoneInfo

* Id
	+ Integer ID of resource zone.
* Name
	+ String name of resource zone.
* Position
	+ Vector3 object that describes location of resource zone.
* Radius
	+ floating-point value that describes the radius of the resource zone, i.e. how big the "ring" is.
* Resources
	+ ResourceInfo object that describes resources available to the resource zone.

#### ResourceInfo

* CrystalTotal
	+ The floating-point value that describes the total amount of Crystal resources.
* CrystalMax
	+ The floating-point value that describes the max amount of Crystal resources.
* MetalTotal
	+ The floating-point value that describes the total amount of Metal resources.
* MetalMax
	+ The floating-point value that describes the max amount of Metal resources.
* OilTotal
	+ The floating-point value that describes the total amount of Oil resources.
* OilMax
	+ The floating-point value that describes the max amount of Oil resources.
* ScrapTotal
	+ The floating-point value that describes the total amount of Scrap resources.
* ScrapMax
	+ The floating-point value that describes the max amount of Scrap resources.

### AI

#### I:GetAIMovementMode(index)

* Takes in the integer index of the AI mainframe to get movement mode from.
	+ Returns the string name of the AI movement mode. Possibilities: "Off", "Manual", "Automatic", "Fleet".

#### I:GetAIMovementMode(index)

* Takes in the integer index of the AI mainframe to get movement mode from.
	+ Returns the string name of the AI firing mode. Possibilities: "Off", "On".

### Propulsion

#### I:TellAiThatWeAreTakingControl()

* This will stop the AI from moving the ship. Basically does the same thing as what happens when the user presses a key when by a controller.

#### I:RequestControl(mode,type,drive)

* This takes in an enumerated integer for mode (0 for water mode, 1 for land mode, and 2 for air mode), another one for type (0 for left yaw, 1 for right yaw, 2 for left roll, 3 for roll right, 4 for pitch up, 5 for pitch down, 6 for "increase", 7 for "decrease", 8 for primary drives) and any number from 0 to 1 for the non-main-propulsion drives, and -1 to 1 for primary propulsion drives.
	+ This serves as a way to effect the ship's drives, similarly to how one controls a ship manually, in a more general fashion compared to the other methods.

#### I:RequestThrustControl(type)

* This takes in an enumerated integer for the control type (0 for forwards, 1 for backwards, 2 for right, 3 for left, 4 for up, 5 for down, 6 for roll right, 7 for roll left, 8 for yaw right, 9 for yaw left, 10 for nose up, 11 for nose down)
	+ This will request the built in thrust control to perform the action given by the control type. Does the same thing as a manually-controlled thrust controller.
	+ Warning: this will override other propulsion systems in order to provide torque-free thrust.

#### I:RequestThrustControl(type, scale)

* Takes in an enumerated integer with the same values as I:RequestThrustControl(type), but also a number between 0 and 1 as a scaling factor
	+ Same functions and warnings as I:RequestThrustControl(type).

#### I:RequestWaterForwards(drive)

* Takes in a numerical value clamped in between 5 or -5.
	+ This will request propellers set to the main drive to push forwards for a singular time step, based on the drive value. This is what the Naval AI uses.

#### I:RequestComplexControllerStimulus(stim)

* Takes in an enumerated integer for the requested stimulus. (0 for none, 1 for T, 2 for G, 3 for Y, 4 for H, 5 for U, 6 for J, 7 for I, 8 for K, 9 for O, 10 for L, 11 for up, 12 for down, 13 for left, 14 for right)
	+ Requests a complex stimulus like the complex controller.

**I:GetDrive(mode)**

* Takes in an enumerated integer for the drive fraction to be returned. (0 for water, 1 for air, 2 for primary, 3 for secondary, and 4 for tertiary)
	+ Returns the current main drive fraction for the selected drive.

**I:GetInput(mode, type)**

* Takes in two enumerated integers, with the same values as I:RequestControl(mode, type, drive).
	+ Gets the current drive fraction for the specified mode and type.

#### I:MoveFortress

* Takes in a Vector3, but us limited to one meter.
	+ Moves the fortress in any direction.

### Self Awareness

#### I:GetConstructPitch()

This is in degrees between 0 and 360. Note that unlike the HUD indicator, positive represents the nose-down direction.

### Components

Component types are as follows:

* 0: Balloon deployers
* 1: Drive maintainers
* 2: Air pump
* 3: Resource gatherer
* 4: Oil drill
* 5: Ammo processor
* 6: Oil processor
* 7: Tractor beam
* 8: Hydrofoil
* 9: Propulsion
* 10: Shield projector

## Tables

### TargetInfo

* Valid
* Priority
* Score
* AimPointPosition
* Team
* Protected
* Position
* Velocity
* PlayerTargetChoice
* Id

### TargetPositionInfo

* Valid
* Azimuth
* Elevation
* ElevationForAltitudeComponentOnly
* Range
* Direction
* GroundDistance
* AltitudeAboveSeaLevel
* Position
* Velocity

### BlockInfo

* Position
* LocalPosition
* LocalPositionRelativeToCom
* Forwards
* LocalForwards
* Rotation
* LocalRotation

### WeaponInfo

* Valid
* LocalPosition
* GlobalPosition
* Speed
* CurrentDirection
* WeaponType
* WeaponSlot
* PlayerCurrentlyControllingIt

### MissileWarningInfo

* Valid
* Position
* Velocity
* Range
* Azimuth
* Elevation
* TimeSinceLaunch
* Id

### FriendlyInfo

* Valid
* Rotation
* ReferencePosition
* PositiveSize
* NegativeSize
* CenterOfMass
* Velocity
* UpVector
* RightVector
* ForwardVector
* HealthFraction
* SparesFraction
* AmmoFraction
* FuelFraction
* AxisAlignedBoundingBoxMinimum
* AxisAlignedBoundingBoxMaximum
* BlueprintName
* Id