Device Scripting
Introduction
Device scripting is core to creating an Off Grid Mission, they are incredibly extensible and are useful for a multitude of tasks including forwarding your missions plot and world building. Each device that the player can hack into will have a device script, devices can share scripts if they're similar enough or have their own bespoke scripts.
Script Example
Let's start with a quick device example and build up from there. One of the Off Grid story missions finds the player needing to hack into the office hand dryers.
Here's a basic example that we'll build upon: It's not as bad as it looks!
device = { -- The game calls this function when the player tries to interact with the device, -- It determines if the player has permission to view the devices GUI canAccess = function() return true end, -- This determines how often the update function gets called -- In this example, we'll call it once a second updateRate = 1.0, update = function() print("Updating!") end, -- The gui table controls the user interface for the device gui = { -- For the moment, this can only be ncurses, but will eventually allow different styles for your gui type = "ncurses", -- The text in the title bar of the gui header = [[Our test hand dryer]], -- The RGB value of the background backgroundColour = {0.95, 0.65, 0.19}, -- The RGB value of the button highlights highlightColour = {0.21, 0.48, 0.74}, -- Here we set up the list of buttons the user can click on buttons = { { -- The name of the first button name = "Test button", -- Code to execute when it's clicked onClick = function() print("test button clicked!") end, -- The list of sub buttons, these appear as options when the main button is clicked subButtons = { { -- Name of the sub button name = "Test subbutton", -- Sub button logic when clicked onClick = function() print("test subbutton clicked!") end, }, } } }, }, }
Receiving Data
Devices can set up a callback for when they receive data, this is done by adding the following to the devices Lua table:
device = { ..., OnReceiveData = function(dataTable) -- Your code here! end, ..., }
The OnReceiveData callback will be triggered when the device is the recipient of the Mission.SendData function.
What do I do now?
Now you've read through and got an idea of how to build up what your interface looks like you might be looking at ways to expand what your device does.
What's important to remember is all Lua Apis are available in device scripts meaning they can:
- Trigger sounds
- Start and stop particle effects
- Complete and start new objectives
- Send data to the player and other devices
Suggested next topic to read up on: Lua Apis