Lua Scripting

From Dual Universe Wiki
Jump to: navigation, search
A visualization of a Distributed Processing Unit

Dual Universe gives players the opportunity to optimize or automate certain parts of constructs through scripting using the Lua programming language. Lua is very simple, and one of easiest coding languages to learn. In Dual Universe, each Element contains its own set of values and functions. An engine can exert a force, a sensor can detect an object, a door can open. Each of the values in these elements has the potential to be used in a script. An engine can be told how much force to exert and when, as its thrust is an assignable value. A door can be opened or closed, and whether it is open or closed is another value. The interaction between all of the elements in a construct is orchestrated by the script within its Distributed Processing Unit (DPU), which resides within a constructs Core Unit.

Distributed Processing Units[edit | edit source]

DPUs can be used by players to set up automated behaviors or reactions in constructs that activate in response to pre-set conditions. Players can add Lua scripts to DPUs, and each DPU has "slots" into which elements can be inserted, which allows the DPU to use its Lua scripts to affect the inserted element. Each DPU has several event handlers, each with its own filter, which allows the player to set conditions that activate the DPU. When the filter conditions for an event handler are met, the corresponding Lua code for that filter is executed. The code can use or assign any of the values associated with the elements that are connected to the DPU.

For example: A player can connect a DPU to a locked door and a series of sensors, with the filter requirement being set to unlock the door when the sensors are triggered in a certain order.

Multiple Players and Scripts[edit | edit source]

Scripts run from the computer of the script owner, but the text of the script is synchronized with all players within render distance, so its effects can still be seen and/or triggered even if the player running the script isn't within visual range of the one triggering the script. The script's actions are synchronized by the server for all players. Even though scripts are run on the client's computer, several players can still simultaneously run different scripts that were created by a single player (and thus running on that one players computer), and all players can see the script and its effects. The only exception is that there cannot be two players controlling the same element at the same time. A player having rights (via RDMS) to use the scripted machine will have access to the in-game scripting editor, and will be able to reverse engineer the script.

In-Game Editor[edit | edit source]

In-Game Editor (Pre-Alpha), displaying example code for a button activating a door.

The in-game script editor will be the primary tool for creating, editing, and viewing Lua script. The editor screen is broken into elements on the left-hand side, event handlers in the middle, and the raw code on the right. The editor enables user to quickly create script by providing a series of predefined functions that can be invoked and events that can occur associated with each element.[1]

Limitations[edit | edit source]

Certain limitations have been implemented to ensure that some aspects of the game are not devalued for players.

  • Scripts will only run if a player is within a particular distance of the Core Unit running the script.
  • Weapons cannot be activated by Lua. Their state can only be read.
  • Mining cannot be scripted to any extent; mining can only be done by a player using their Nanoformer.

Note[edit | edit source]

In time, this page will become a much more comprehensive guide on scripting with Lua. For now, with so little information available, it is merely a summary.

See Also[edit | edit source]

External Links[edit | edit source]

  1. DevBlog: Lua Script and Distributed Processing Units (09/18/2015)
  2. Dual Universe Pre-Alpha Tutorial: Lua Scripting (November 24, 2017) First Developers' tutorial related to the Lua Scripting.

References[edit | edit source]

  1. Dual Universe YouTube Channel, "Dual Universe DevDiary Updates - July 2017 | Pre-Alpha Video", Timestamp: 0:48 - 1:56. 07/31/2017.