-
Notifications
You must be signed in to change notification settings - Fork 0
Creating a Peripheral
``This will be a quick little tutorial on how to create your own peripherals for the mod. This tutorial assumes that you have some knowledge on Lua and how to create/edit objects for Starbound.
First off, your peripheral must either an input or output node available. Once that's out of the way, you'll have to attach a Lua script to said object, with the update time dependent on what your peripheral does. For example, if your peripheral relies on object hooks such as onInteraction(), or isn't trying to send data to the computer, the update time can most likely be set to zero. However, if your peripheral needs to use the object hook update() in any way to interact with the computer, then it probably should be a nonzero value, with said value being up to you to decide.
Returns: string: This function will return the type of peripheral your object is.
Returns: string: This function will return the UUID of your peripheral so that it may be used along multiple copies of it.
The following code (or any variation of it) is recommended to be used for the generation of such uuids:
function newUUID()
local uuid = {[9]="-",[14]="-",[19]="-",[24]="-"}
for i = 1, 36 do
uuid[i] = uuid[i] or string.format("%x", math.random(0, 15))
end
return table.concat(uuid)
end
-- Make sure to actually use the function.
function init()
storage.address = storage.address or newUUID()
end
-- And finally your peripheral function
function peripheralAddress()
return storage.address
endThis function lets you grab the entityID of the computer which is connected to your peripheral. Once storing it in a local somewhere, you can use it to queue events on the computer system that's currently using this peripheral. There are two ways to go about it:
If your peripheral is server side, meaning that it doesn't require any sort of special interface to show data to the user that was sent from the computer (such as a monitor), then you'll be using the following function:
world.callScriptedEntity(number entityID, string eventName, ...)
The entityID is the id that was passed to you via peripheralBind(). Everything after the eventName is arguments being passed with the event your queueing, and aren't required to give, meaning you can queue an event with just the event name.
If your peripheral is client-side, meaning it needs a way to dynamically show the data received from the computer to the user (such as a monitor), then you'll have to wait until I finish this tutorial to go more in depth about this. =P
Returns: table: This function, if defined, will return a table, ideally full of functions. You'll use this if you want the computer to have access to a table of methods to interact with your peripheral
Probably not. It would mean having to ensure compatibility with each and every mod that I support whenever a new update for them arrives. Making peripherals was purposefully made rather easy to allow other mod authors who want to create peripherals easily maintain said peripherals with future updates of this mod, as the peripheral system is likely to stay much like it is now, if it were to change at all, that is.