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

Activating redstone using tablet.

Question

I want a program on my tablet that when activated, sends a message to a server using a linked card and the server then activates some redstone around a redstone I/O. Can anyone make that?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

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