Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
GGCrosby

Activating redstone using tablet.

Question

1 answer to this question

Recommended Posts

  • 0

rsClient.lua

local component = require "component"
local event = require "event"

local tunnel = assert(component.tunnel, "primary tunnel component required")
local args, timeout = {...}, nil

if args[1] and (args[1] == '-t' or args[1]:match "--timeout=%d+") then
  timeout = tonumber(args[2]) or tonumber(args[1]:match "--timeout=(%d+)")
end

tunnel.send("rs_info") -- # ask server for redstone interface details
local isAnalog, side, level, color = select(6, event.pull(timeout or 5, 'modem_message', tunnel.address, nil, 0, 0))

tunnel.send("rs_update", side, level < 15 and 15 or 0, isAnalog and nil or color) -- # toggle redstone output value
local success, reason = select(6, event.pull(timeout or 5, "modem_message", tunnel.address, nil, 0, 0))

if not success then
  io.stderr:write(reason..'\n')
else
  print('redstone interface updated')
end

rsServ.lua

--
local component = require "component"
local event = require "event"
local colors = require "colors"
local sides = require "sides"

local tunnel = assert(component.tunnel, "primary tunnel component required")
local rs_address, side, color = ...

rs_address = assert(component.get(rs_address))
side = assert(sides[side], "invalid side")

if color then
  color = assert(colors[color] and color, "invalid color")
end

while true do
  local ev = {event.pullMultiple('interrupted', 'modem_message')}

  if ev[1] == 'interrupted' then
    break
  elseif ev[1] == 'modem_message' and ev[2] == tunnel.address then
    if ev[6] == 'rs_info' then
      local isAnalog = color and false or true
      local rs_state

      if isAnalog then
        rs_state = component.invoke(rs_address, 'getOutput', side)
        tunnel.send(true, side, rs_state)
      else
        rs_state = component.invoke(rs_address, 'getBundledOutput', side, color)
        tunnel.send(false, side, rs_state, color)
      end
    elseif ev[6] == 'rs_update' then
      local output_side, output_level, output_color = table.unpack(ev, 7)
      local success, reason

      if output_color then
        success, reason = pcall(component.invoke, rs_address, 'setBundledOutput', output_side, output_color, output_level)
      else
        success, reason = pcall(component.invoke, rs_address, 'setOutput', output_side, output_level)
      end

      tunnel.send(success, reason)
    end
  end
end

Should do the trick :)

Start client with `rsClient 5`, will timeout in 5 seconds if it cant contact the server.

Start server with `rsServ 45af south`, where '45af' is the abbreviated address of the redstone component and 'south' is the direction to output the signal.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.