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

Bundled Cables and RedPulse

Started by xtsu, 25 August 2012 - 03:52 AM
xtsu #1
Posted 25 August 2012 - 05:52 AM
I have looked in several places and still can't seem to get what I want to do to work.

I want to send out a red pulse to a specific color wire attached to a bundle cabled that is attached to the computer. I would like to input the number of pulses or hard code it in.

For example:

Wtrite ("How many items do you want? ")
input = read()
redstone.setBundleOutput("left", shell.run("redpulse", "input", "1"), colors.green)

Also, I am not sure how to end the program to go back to the main screen as in startup.
Kazimir #2
Posted 25 August 2012 - 01:48 PM
Use instead of the redpulse, this function:

function LedPulse(color, age)
rs.setBundledOutput("left", color)
sleep(age)
rs.setBundledOutput("left", 0)
end

Example of use:

local function LedPulse(color, age)
   rs.setBundledOutput("left", color)
   sleep(age)
   rs.setBundledOutput("left", 0)
end

term.clear() term.setCursorPos(1,1)
write("color: ") local c=read()
write("age: ") local a=read()
term.clear() term.setCursorPos(1,1)

LedPulse(c,a)
xtsu #3
Posted 25 August 2012 - 02:46 PM
I have tried using that but am unsure how to use / call it right? I get errors that state expecting an int but got a string. Here is what I have tried:


write ("how many items would you like?")
age = read()
color = "colors.green"
function LedPulse(color, age)
rs.setBundledOutput("left", "color")
sleep(age)
rs.setBundledOutput("left", 0)
end

I am almost thinking I need to use the bit number for the color and need to make some kind of loop?
Kazimir #4
Posted 25 August 2012 - 02:54 PM
To call the function, you must first initialize it.
In principle you can do so:

write("how many items would you like?")
age = read()
color = colors.green
rs.setBundledOutput("left", color)
sleep(age)
rs.setBundledOutput("left", 0)
xtsu #5
Posted 25 August 2012 - 03:34 PM
but in that example the age is just how long it sleeps for. I want to be able to say get 6 iron from a chest. So I need to pulse the green cable 6 times.
Kazimir #6
Posted 25 August 2012 - 03:42 PM
Perhaps you would like to create a program like this:

l={[1]="item1",[2]="item2",[3]="item3",[4]="item4",[5]="item5"}
local function LedPulse(color)
   rs.setBundledOutput("left", color)
   sleep(0.1)
   rs.setBundledOutput("left", 0)
end
while true do
  term.clear() term.setCursorPos(1,1)
  print("what items you want?")
  print(l[1]," ",l[2]," ",l[3]," ",l[4]," ",l[5])
  local c=read()
if c==l[1] then c=1
 elseif c==l[2] then c=2
 elseif c==l[3] then c=4
 elseif c==l[4] then c=8
 elseif c==l[5] then c=16
end
  term.clear() term.setCursorPos(1,1)
  print("how many items would you like?") local a=read()
for mv=1,a do
  LedPulse(c)
  sleep(0.3)
end
end
xtsu #7
Posted 25 August 2012 - 04:02 PM
when you list the c=1 c=2 c=4 and so on, is that hard coded in minecraft? example white insulated wire always has a value of 1? and orange would be 2? and magenta 4? or does it go by position coming off the bundled cable?
Kazimir #8
Posted 25 August 2012 - 04:07 PM
so coded in RedPower http://computercraft.info/wiki/index.php?title=Colors_(API)
Cranium #9
Posted 25 August 2012 - 04:07 PM
He's actually calling back to that first line you see there. He's basically comparing if the input you enter is equal to any of those options at the top.
BigSHinyToys #10
Posted 25 August 2012 - 04:28 PM
This is a complex program I just wrote and commented. It works like other programs in CC you give it inputs when you run it.
This program contains a function pulse() that you can use in other programs.
Spoiler

local tArgs = {...}
local tSides = rs.getSides() -- this gest a list of the sides front back left right top bottom and and puts it in a table
local tSorted = {} -- this will store a list to compair against latter
for i = 1,#tSides do -- this will loop ounce for eatch of items in tSides this should be 6
    tSorted[tSides[i]] = "" -- use the strings from from tSdies as elemsnts in the table.
end
local function pulse(sSide,sColour,nRepeat) -- decalre pulse function
    for i = 1,nRepeat do -- start loop it will run for the number stored in nRepeat
	    sleep(0.3) -- pause bstween redstone change
	    rs.setBundledOutput(sSide,colors[sColour]) -- turn on the color
	    sleep(0.3) -- pause bstween redstone change
	    rs.setBundledOutput(sSide,0) -- turn off the color
    end
end
if #tArgs == 3 then -- check for three input values from user
    if tSorted[tArgs[1]] then -- test if the string given by the user is a elemsnt in this table. it will be true if et exists
	    if colors[tArgs[2]] then -- test if it is realy a color
		    local nLoop = tonumber(tArgs[3]) -- change the string to number if it cant it will be nill
		    if nLoop then
			    print("pulsing "..tArgs[1].." side "..tArgs[2].." "..tostring(nLoop).." times.")
			    pulse(tArgs[1],tArgs[2],nLoop)
		    else
			    print("not a number")
			    print("usage pulse <side> <color> <loops> ")
		    end
	    else -- if not color then tell then
		    print("not a color")
		    print("usage pulse <side> <color> <loops> ")
	    end
    else -- if the user given srring is not one of the sides top bottom left right front back tell them
	    print("not a side")
	    print("usage pulse <side> <color> <loops> ") -- tell the user how to use program
    end
else -- if not three input values then
    print("usage pulse <side> <color> <loops> ") -- tell the user how to use program
end
example usage if it was named bundle on the computer.

bundle left red 5
xtsu #11
Posted 25 August 2012 - 04:34 PM
Ok… now lets say I wanted to step it up a notch. what if I wanted to tell the computer to run the solar panel program and it would fetch the items I needed. But what if it wasn't always to the left? I have 4 bundled cables hooked to the computer. the end goal would be to tell it go fetch so many iron from left, glass from right and so on. I know where each is and how many.

I think I could modify this program to do that.
xtsu #12
Posted 25 August 2012 - 04:41 PM
BigSHinyToys: That function looks a bit easier for what I want to do with auto crafting as I could keep calling that function over and over again in other programs.

My issue is, how do I call the program "bundle" in say a program named "Solar Panel"?

Then how do I feed it the variables? I would know them. As in a solar panel needs 3 glass and such.
BigSHinyToys #13
Posted 25 August 2012 - 04:51 PM
This is how I would do it
Spoiler

local tArgs = {...}
local tSlections = {}
tSlections.iron = {side = "left",color = "red"}
tSlections.glass = {side = "back",color = "green"}
tSlections.redstone = {side = "left",color = "pink"}
local function pulse(sSide,sColour,nRepeat)
    for i = 1,nRepeat do
	    sleep(0.3)
	    rs.setBundledOutput(sSide,colors[sColour])
	    sleep(0.3)
	    rs.setBundledOutput(sSide,0)
    end
end
if #tArgs == 2 then
    local nLoops = tonumber(tArgs[2])
    if tSlections[tArgs[1]] and nLoops then
	    print("Retreving "..nLoops.." "..tArgs[1].." for you sir")
	    pulse(tSlections[tArgs[1]].side,tSlections[tArgs[1]].color,nLoops)
    else
	    print("Usage is <item> <amount>")
    end
else
    print("Usage is <item> <amount>")
end
just ask if something doesn't make scene and I will explain
BigSHinyToys #14
Posted 25 August 2012 - 04:59 PM
you don't need to call this program here is a function version. just put this in your code at the top and call the get function when you need a item retrieved.
Spoiler

local tSlections = {}
tSlections.iron = {side = "left",color = "red"}
tSlections.glass = {side = "back",color = "green"}
tSlections.redstone = {side = "left",color = "pink"}
local function pulse(sSide,sColour,nRepeat)
	for i = 1,nRepeat do
		sleep(0.3)
		rs.setBundledOutput(sSide,colors[sColour])
		sleep(0.3)
		rs.setBundledOutput(sSide,0)
	end
end
function get(nQuantity,sItem)
	pulse(tSlections[sItem].side,tSlections[sItem].color,nQuantity)
end
get(50,"iron")
xtsu #15
Posted 25 August 2012 - 05:29 PM
in the second example if I wanted cobblestone I would make a tSlections.cobblestone and where it was then I could call get(3, cobblestone) and it would get 3 cobble stone?
BigSHinyToys #16
Posted 25 August 2012 - 05:39 PM
in the second example if I wanted cobblestone I would make a tSlections.cobblestone and where it was then I could call get(3, cobblestone) and it would get 3 cobble stone?
you would make with the correct side a color

tSlections.cobblestone = {side = "top",color = "green"}
and call it with

get(3,"cobblestone")
you must use "" for it to work.
but basically yes as you said
xtsu #17
Posted 26 August 2012 - 08:10 AM
BigSHinyToys: In the example where it says fetching x number of items for you, would it be possible for it to say something when it is finished?
BigSHinyToys #18
Posted 26 August 2012 - 09:41 AM
BigSHinyToys: In the example where it says fetching x number of items for you, would it be possible for it to say something when it is finished?
yes it is possible just do this.

print("Retreving "..nLoops.." "..tArgs[1].." for you sir")
pulse(tSlections[tArgs[1]].side,tSlections[tArgs[1]].color,nLoops)
print("complete") -- add this here bellow this^