This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SimpleMajority's profile picture

[LUA][QUESTION] Redpower2 and question about setting timed events

Started by SimpleMajority, 02 April 2012 - 04:00 AM
SimpleMajority #1
Posted 02 April 2012 - 06:00 AM
So my idea is to have a bundled output running off the system and individual wires running at different times to handle my sorting, but in the help file (which isn't very helpful imo) I don't see anyway of using boolean to turn the wires on and off.

using simple code this is how I am trying to get the system to work

// This is a simple form of what I am trying to achieve
// In the production line these would need to have different
// Timers that would feed off of one computer, so different
// Wires would be needed and a bundled wire to have it all
// Tied into one computer.
while true do
    redstone.setOutput("back",true)
    sleep(1)
    redstone.setOutput("back",false)
    sleep(1)
end
Hawk777 #2
Posted 02 April 2012 - 06:10 AM
You want the “redstone.setBundledOutput” function. It sets all the outputs simultaneously using a single value, with the colours being the binary bits of that value (so it will turn off all wires that you don’t explicitly keep turned on). I wrote this helper function to let me turn an individual colour on or off without affecting the other colours:


-- Function setWire(side, colour, value)
--
-- Sets a single wire in a bundled cable in a single direction to a specific value.
--
-- Parameters:
--   side - the side of the computer console on which the bundled cable is attached
--   colour - the colour of the wire to turn on or off
--   value - true to turn the wire on, or false to turn it off
setWire = function(side, colour, value)
	assert(type(side) == "string", "rwutil.setWire: "side" must be a string")
	assert(type(colour) == "number", "rwutil.setWire: "colour" must be a number")
	assert(type(value) == "boolean", "rwutil.setWire: "value" must be a boolean")

	local old = redstone.getBundledOutput(side)
	if value then
		redstone.setBundledOutput(side, bit.bor(old, colour))
	else
		redstone.setBundledOutput(side, bit.band(old, bit.bnot(colour)))
	end
end

You would do something like “setWire("top", colours.red, true)” to turn the red wire on top of the computer on while touching none of the other wires, or “setWire("top", colours.red, false)” to turn it off.
SimpleMajority #3
Posted 02 April 2012 - 06:54 AM
interesting I will give it a spin. I am learning lua as I go lol. I know in javascript there is a way of getting the time, is there something like that in lua. My thought is having the reactor tied to a computer and shut it down at daylight (compact solars take over at dawn) then restart the reactors at dusk.
Luanub #4
Posted 02 April 2012 - 07:34 AM
os.time() will return the current Minecraft world time.
SimpleMajority #5
Posted 02 April 2012 - 08:17 AM
oh nice. do you know if it is based on a 24 hour clock?
Advert #6
Posted 02 April 2012 - 01:50 PM
oh nice. do you know if it is based on a 24 hour clock?

You could find that out yourself, as it's based on the minecraft world clock, i.e each 'day' is about 20 minutes long.