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

mpm.rstools: Simplify your redstone!

Recommended Posts

Introduction

 

Are you creating the secret underground base? A pyramid maze with all kinds of traps? Or just your high security door lock?

Then it's very likely that you are using redstone. More complex designs require bigger circuits or computers. (redstone computers?)

Programming with redstone cards or blocks is quite straightforward, but it can be quite annoying to always repeat yourself:

local component = require("component")
local sides = require("sides")
local colors = require("colors")
local rs = component.redstone
rs.setBundledOutput(sides.north, colors.blue, true)   --close entrance
os.sleep(1)
rs.setBundledOutput(sides.north, colors.green, false) --open exit
os.sleep(10)
rs.setBundledOutput(sides.north, colors.green, true)  --close exit
os.sleep(1)
rs.setBundledOutput(sides.north, colors.blue, false)  --open entrance

This library makes things easier and your code more expressive:

local component = require("component")
local rstools = require("mpm.rstools")
local rs = component.redstone
--inverted to make true == open
local entrance = rstools.digital("output", rs, "north", "blue").inverted
local exit     = rstools.digital("output", rs, "north", "green").inverted
entrance(false)             --close entrance
os.sleep(1)
exit:pulse(10, true, false) --open exit for 10 seconds
os.sleep(1)
entrance(true)              --open entrance

Documentation

rstools.analog(type, address/proxy, side/"wireless"[, color]) -> object
rstools.digital(type, address/proxy, side/"wireless"[, color]) -> object

Both functions need a type which is either the string "input" or "output".
While "input" objects read the input value, you can use "output" objects to read and write output values.

The second parameter defines the redstone component to be used. (either using its address or its proxy)

The third parameter defines the side to be used. You can use the numeric value or the name of the side.
Wireless redstone has the side "wireless".

For bundled cables you can use the fourth parameter to specify the color. (numeric value or name)
The color "all" makes the object accept and return tables of values.

analog vs. digital
"analog" objects work with numeric values. (e.g. 0 - 15 for vanilla redstone)
"digital" objects work with boolean values. Wireless component functions only return and accept boolean values, so they are converted to 0 and math.huge.
object() -> returns current value
object.inverted -> an inverted object (true -> redstone off, false -> redstone on, only useful for digital objects)

type == "output" only:
object(value) -> changes output
object:pulse(duration, value[, originalValue]) -> overrides the output for 'duration' seconds, then restores original value
object:toggle() -> inverts the output (only useful for digital objects)

Depencencies

 

Software

OpenOS

 

Hardware

Redstone Component

 

Installation

 

Download the file and save it as the library "mpm.rstools".

 

Download (last update: 29.01.16)

 

github

mkdir /home/lib/mpm
cd /home/lib/mpm
wget 'https://raw.githubusercontent.com/mpmxyz/ocprograms/master/home/lib/mpm/rstools.lua'

Known Issues

 

None.

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
Reply to this topic...

×   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.