Control Unit

From Dual Universe Wiki
(Redirected from Control Units)
Jump to: navigation, search
Concept art of a Control Unit

The Control Unit is an element that can be though of as a computer. Control Units run lua scripts on-board constructs when they are activated. Before elaborating on Control Units, the user must first understand what a Distributed Processing Unit is.

Distributed Processing Units[edit | edit source]

DPUs are computers that can perform a number of functions. They are found in a variety of predefined game elements. Most DPUs cannot be modified; however, Control Units provide the player with a programmable computer that can perform a variety of tasks, including controlling the DPUs in other predefined game elements.

The DPU is initiated when the player activates the Control Unit. It is entirely possible to have multiple DPUs present and active on the same construct at the same time.

Customization[edit | edit source]

The DPU inside of a Control Unit is special because there will be a GUI to freely customize it (plug things into the slots, define event handlers, etc), as well as define a set of events that the DPU is capable of emitting (event emission is done via a special LUA syntax inside of the scripts). It is also possible to define a set of functions associated with the DPU, and the corresponding LUA code that should be executed when this function is requested. There is in fact a DPU inside each Element, and the events and functions of this Element are actually the events and functions of its DPU. It is not really Elements that are plugged into the slots of a Control Unit's customizable DPU, but rather other DPUs. It can be the DPU of Elements, but it can also be more abstract DPUs.

Other types of DPUs[edit | edit source]

One particularly important "abstract" DPU is the System DPU. This DPU is capable of emitting events when keys are pressed. It is almost always desirable to plug in the System DPU, because this allows the player to control a construct's scripts with keystrokes bound to actions. Thus, typically there will be several event handlers in a custom DPU to catch action events emitted by the System DPU. The System DPU is also capable of emitting "timeout" events when a timer is due, or at regular intervals, and many other useful functionalities.

Control Unit

Scripting with DPUs[edit | edit source]

There needs to be at least one Control Unit on a ship, and its DPU must be customized. Inside this DPU, the System DPU (typically in the "system" slot) must be plugged in, plus at least 3 engines pointing upwards to lift the ship, and 2 more engines at the back of the ship to make it move forward. There also needs to be an inclinometer, which is an Element that provides the getPitch and getRoll functions, to know about the pitch/roll angles of the ship. Next, set a timer with the system DPU (call the system.setTimer(0.1) function to set the update every 0.1 second) and catch the corresponding timeout event. The LUA script can then be set to query the inclinometer about the pitch/roll and use these values to correct the intensity of thrust power in the engines (using the setPower function) to stabilize the ship tilting. And of course, the action events can be caught from the System DPU to inform the script about the direction in which the player wants to stir the ship. [1]

See Also[edit | edit source]

Lua Scripting