Last active
March 11, 2022 10:10
-
-
Save adamnejm/07f4d0dee959a32215ab169cecc0253b to your computer and use it in GitHub Desktop.
Starfall - Link Chair via Wire Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--@name Link Chair via Wire Example | |
--@author Name | |
--@server | |
local owner, client, chip, world = owner(), player(), chip(), entity(0) | |
-- Just a simple function that will set a "random" color to the provided entity | |
local function set_random_color(ent) | |
local color = Color(math.random(0, 360), 1, 1):hsvToRGB() | |
ent:setColor(color) | |
end | |
-- Setup inputs for the Wire interface, only one in this case - 'Pod' which will only accept 'entity' values | |
wire.adjustPorts { ["Pod"] = "entity" } | |
-- Add a callback when any input changes, this will also run on wire interface setup (placing / refreshing a chip) | |
hook.add("Input", "SetChair", function(name, value) | |
-- If the name isn't Pod or its value isn't valid (often not yet linked) then we don't care | |
if name ~= "Pod" or not value:isValid() then return end | |
-- Use the received value | |
set_random_color(value) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment