Jump to content




Help with Bundled cable & multiple spawners


19 replies to this topic

#1 Jinxtah

  • Members
  • 8 posts

Posted 27 January 2013 - 12:45 PM

Title: Help with Bundled cable & multiple spawners

Maybe there's a better title than that I don't know.
First an explanation of the system:
I have 10 lvl 5 soul crystal spawners (playing FTB). The spawners can be turned off by supplying a redstone signal. I've set up a reciever at each spawner, and set up a transmitter for each reciever somewhere else.
From those recievers I have run bundled cable with various colors up to an advanced computer.
The computer startup program is basically just a bunch of lines saying that spawner xx is inactive.
Now I want to be able to write "cow" or whatever to turn on the cow farm, and have the text change color for the farm.
I've done this myself by just wrapping the monitor and changing the text color from red on inactive to green and write active.
Once the sleep timer has expired the program runs the startup script again so all spawners are listed as inactive again on the monitor.

The problems I'd like help with are the following:

Once I run a program I can't run others while it's running. I'd like to get some code (or help with coding failing that) that when I wrote "cow" it turns on the spawner and returns to the command prompt again while keeping the green Active state on the monitor. Then when I write "cow" again it will shut down the spawner and return to the red Inactive for the spawner. This should hopefully enable me to run multiple spawners at once.



This is the code I have for the startup script which lists all the spawners as inactive:

monitor = peripheral.wrap("top")
monitor.clear()
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 1)
monitor.write("Cow Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 1)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 2)
monitor.write("Spider Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 2)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 3)
monitor.write("Skeleton Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 3)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 4)
monitor.write("Endermen Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 4)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 5)
monitor.write("Pigmen Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 5)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 6)
monitor.write("Blaze Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 6)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 7)
monitor.write("Zombie Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 7)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 8)
monitor.write("Creeper Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 8)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 9)
monitor.write("Wither Skels Farm:")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 9)
monitor.write("Inactive")
monitor.setTextColor(colors.white)
monitor.setCursorPos(1, 10)
monitor.write("Slime")
monitor.setTextColor(colors.red)
monitor.CursorPos(20, 10)
monitor.write("Inactive")

This is the very simple code I wrote for turning the cow spawner on for 5 seconds and off again:

redstone.setBundledOutput("back", colors.blue)
sleep(5)
redstone.setBundledOutput("back", 0)
I of course put in a monitor.clear() and then change the red to green on the text color and text from inactive to active. I then just put a line telling the program to run the startup script at the end.

These are the colors for the spawners:
Blue = Cow
Yellow = Spider
Red = Skeleton
Green = Endermen
White = Blaze
Purple = Pigmen
Grey = Zombie
Brown = Creeper
Lightblue = Slime
Orange = Wither Skeleton

I'm hoping someone will help me out :)
I'm hoping there's a better way to do it all than how I did it, and perhaps some sort of way for me not to write all the spawner states again and again for each program, so maybe the computer detects what is on and lists it as active and changes the text from inactive to active.
If there is something I didn't elaborate on which needs elaboration, then let me know and I'll do my best to explain.

Thanks in advance.

#2 Jinxtah

  • Members
  • 8 posts

Posted 28 January 2013 - 01:35 AM

I tried to fiddle around with it, and came up with this faulty code to make things work.

redstone.getBundledOutput("back", colors.yellow)
if Output == false
then
  redstone.setBundledOutput("back", colors.yellow)
end
if Output == true
then
  redstone.setBundledOutput("back", 0)
end
But this does nothing at all, and I can't for the life of me figure out why. I also tried with BundledInput for line 1 and Input for lines 2 & 6 with no effect.
I'm thinking if there's some way to get this working, I can simply overwrite the startup script line with "Active".
Any pro out there who could lend a hand please? :)

#3 Jinxtah

  • Members
  • 8 posts

Posted 28 January 2013 - 03:26 AM

I now rewrote a few things so that it works with turning on one spawner at a time. Turning on another spawner while one is already active makes the first spawner go inactive. Not exactly what I want, but it'll do for now I suppose.

I'm still hoping someone can help me out with the whole turning on multiple spawners and keeping the input on.

#4 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

Posted 28 January 2013 - 03:41 AM

There's 2 things you can do. the first is using the fs api (which i dont know how it works exactly) to keep note of the list of spawners thats on and off.
The second is using the method jinxtah started with..
for instance if blue = cow and yellow = spider
m = peripheral.wrap("top")
function monitorDraw()
  m.clear()
  if rs.getBundledOutput("back",colours.blue) == true then
    m.setCursorPos(1,1)
    m.write("Cow: active")
  else m.write("Cow: inactive")
  end
  --repeat for other colours
end
while true do
  x = read()
  if x == "cow" then
    if rs.getBundledInput("back",colours.blue) == true then
	  --set output minus blue
    else
	  --set output plus blue
    end
  elseif x == "spider" then
    --repeat above steps
  end
  monitorDraw()
end

fill in the gaps and i think it should work

#5 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 28 January 2013 - 03:47 AM

To toggle only one color without resetting the others, you can do:
local function set(side, color)
  rs.setBundledOutput(side, colors.combine(rs.getBundledInput(side), color) )
end

local function reset(side, color)
  rs.setBundledOutput(side, colors.subtract(rs.getBundledInput(side), color) )
end


#6 Jinxtah

  • Members
  • 8 posts

Posted 28 January 2013 - 04:50 AM

View Postikke009, on 28 January 2013 - 03:41 AM, said:

There's 2 things you can do. the first is using the fs api (which i dont know how it works exactly) to keep note of the list of spawners thats on and off.
The second is using the method jinxtah started with..
for instance if blue = cow and yellow = spider
m = peripheral.wrap("top")
function monitorDraw()
  m.clear()
  if rs.getBundledOutput("back",colours.blue) == true then
	m.setCursorPos(1,1)
	m.write("Cow: active")
  else m.write("Cow: inactive")
  end
  --repeat for other colours
end
while true do
  x = read()
  if x == "cow" then
	if rs.getBundledInput("back",colours.blue) == true then
	  --set output minus blue
	else
	  --set output plus blue
	end
  elseif x == "spider" then
	--repeat above steps
  end
  monitorDraw()
end

fill in the gaps and i think it should work
This doesn't work for me. The lines where you put -- (for example --set output minus blue) makes the line be ignored right? So if I remove the -- then it says it expects an =. If I put that in it expects it some more.
Maybe I'm missing something?

#7 Jinxtah

  • Members
  • 8 posts

Posted 28 January 2013 - 04:52 AM

View PostOrwell, on 28 January 2013 - 03:47 AM, said:

To toggle only one color without resetting the others, you can do:
local function set(side, color)
  rs.setBundledOutput(side, colors.combine(rs.getBundledInput(side), color) )
end

local function reset(side, color)
  rs.setBundledOutput(side, colors.subtract(rs.getBundledInput(side), color) )
end
I'm not really sure what to do with this code. Do I define the side and color for every spawner program, or what do I do? :)

#8 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 28 January 2013 - 05:09 AM

Well, you had this as an example:
redstone.setBundledOutput("back", colors.blue)
sleep(5)
redstone.setBundledOutput("back", 0)
This sets only the blue color as on and then turns all colors off. So this doesn't leave room for the other colors to stay on. Example:
redstone.setBundledOutput("back", colors.blue)
redstone.setBundledOutput("back", colors.green) -- now blue is off and only green is on
sleep(5)
redstone.setBundledOutput("back", 0)
So you can only set one color at a time.

Now, using my function, you can set multiple at a time:
set("back",colors.blue) -- enables blue
set("back",colors.green) -- enables green
sleep(3)
reset("back",colors.green) -- resets green after 3 seconds
sleep(2)
reset("back",colors.blue) -- resets blue after another 2 seconds


#9 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

Posted 28 January 2013 - 05:37 AM

View PostJinxtah, on 28 January 2013 - 04:50 AM, said:

View Postikke009, on 28 January 2013 - 03:41 AM, said:

snip
This doesn't work for me. The lines where you put -- (for example --set output minus blue) makes the line be ignored right? So if I remove the -- then it says it expects an =. If I put that in it expects it some more.
Maybe I'm missing something?
You aren't supposed to just delete the comments (the --) but make your own script there that does what you want, with set output minus blue i meant set the output like how it is now, but without the blue colour. You should be able to do that with the things orwell just posted

#10 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 28 January 2013 - 05:55 AM

You don't even need the stuff that ikke9 posted at all with my method.
For example:
local side = "back"

local mapping = {
  Cow = colors.blue,
  Spider = colors.yellow,
  Skeleton = colors.red,
  Endermen = colors.green,
  Blaze = colors.white,
  Pigmen = colors.purple,
  Zombie = colors.gray,
  Creeper = colors.brown,
  Slime = colors.lightBlue,
  ["Wither Skeleton"] = colors.orange,
}

local function set(side, color)
  rs.setBundledOutput(side, colors.combine(rs.getBundledInput(side), color) )
end

local function reset(side, color)
  rs.setBundledOutput(side, colors.subtract(rs.getBundledInput(side), color) )
end

local function test(side, color)
  return colors.test(rs.getBundledInput(side), color)
end

local function printStatus(side)
  term.setBackgroundColor(colors.black)
  term.clear()
  local line = 1
  for spawner,color in pairs(mapping) do
	term.setTextColor(colors.white)
	term.setCursorPos(1, line)
	write(spawner.." Farm:") -- write the spawner name
	local status = test(side, color)  -- gets the status for the spawner (true/false)
	term.setCursorPos(20, line)  
	term.setTextColor(status and colors.green or colors.red)  -- sets the color to green if its active, red if inactive
	write(status and "active" or "inactive") -- writes the status to the screen
	line = line + 1
  end
end

set(side, mapping["Creeper"]) -- activates the creeper spawner
printStatus(side) -- prints the status to the screen

Ask away about the parts you don't understand. :) You should be able to get started with this snippet.

Edit: fixed a typo in the code

#11 Jinxtah

  • Members
  • 8 posts

Posted 28 January 2013 - 08:12 AM

@Orwell
Thanks so much for trying to help out here. Some of the stuff you wrote is way over my head. Last coding I did was assembly coding like 15 years ago so I'm a bit out of touch :)

I tried to enter your exact code into a program but all it does is return with this: test:44 attempt to index ? (a nil value)

(line 44 is the activates the creeper spawner bit at the end).
I don't really want to ask you to write the whole program for me, but I feel like I have no idea where to go from there. I don't even know how to change it so it's not the terminal it writes to, but a monitor wrapped above the terminal, and incorporate multiple spawners. Should I add it to line 45 with each spawner, or?
This code doesn't look like it's giving me any options when I run it. I mean it doesn't look like it gives me any options to select Cow etc.

I'm sorry if it's a pain, and I understand if you can't be bothered, but I'd appreciate any further help you can provide :)

#12 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 28 January 2013 - 08:37 AM

I accidentally wrote mappings instead of mapping. I edited it in the post. Well, it was meant to get you started. My code includes a set and reset function to toggle the cable color you give as a parameter. A test function that returns true if that color is on and false if it isn't. And a printStatus function that prints the status of each cable in the same manner as you did in the OP. The map 'mapping' maps a string to a color. So mapping["Cow"] gives colors.blue and mapping["Creeper"] gives colors.brown . Thus, to enable the creeper spawner, you do: set(side, mapping["Creeper"]) . You see?

I didn't add in any options like you're talking about. You'd need to alter the printStatus function to keep track of a selected index. Then you'd want to make it higher or lower the index on an up/down key event. On an enter event or something, you'd want to set/reset the color that matches the selected option. And eventually you want to draw a marker (like [ ]) at the option you selected. If you have trouble with some (or all:p) of these steps, feel free to post your questions here. :) But I feel like it's important that I give you directions and you try to figure it out yourself first.

For the monitor, put this at the top of your code:
local monitor = peripheral.wrap( "side" ) -- you know, change side to the side the monitor is on
term.redirect(monitor)
And this at the bottom:
term.restore()


#13 Jinxtah

  • Members
  • 8 posts

Posted 01 February 2013 - 02:15 AM

I tried messing around with it for a few days on and off, but I can't seem to get it to work.
I'll spend a bit more time with it and get back to you, Orwell :)

#14 uh20

  • Members
  • 11 posts

Posted 01 February 2013 - 04:05 AM

first off, set some definitions to make your life easier
cow = colors.green
pig = colors.black
etc.

next, we need to do some tests and an active monitor activity


Quote

monitor = peripheral.wrap("top")
function monitor()
monitor.clear()
monitor.setTextColor(colors.white)
monitor.setCursorPos(1,1)
monitor.write("Cow Farm:")
monitor.CursorPos(20, 1)

if not cowenabled then
monitor.setTextColor(colors.red)
monitor.write("Inactive")
else
monitor.setTextColor(colors.green)
monitor.write("Active")

end

and so on so forth.

instead of


Quote

redstone.setBundledOutput("back", colors.blue)
sleep(5)
redstone.setBundledOutput("back", 0)
use what orwell suggested
wait(5)

use colors.combine and colors.subtract as shown by orwell to combine the colors in with whats already on with the color you want to enable, then just remove the color you enabled with subtract when the value is passed to rs.setBundledOutput

sorry i cant help more completely, i dont have any more time.

#15 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 01 February 2013 - 05:14 AM

View Postuh20, on 01 February 2013 - 04:05 AM, said:

first off, set some definitions to make your life easier
cow = colors.green
pig = colors.black
etc.
I'm curious why the table 'mapping' in the snippet I posted isn't good enough for this? It allows for traversing the whole table without knowledge of each separate spawner.

View Postuh20, on 01 February 2013 - 04:05 AM, said:

next, we need to do some tests and an active monitor activity


Quote

monitor = peripheral.wrap("top")
function monitor()
monitor.clear()
monitor.setTextColor(colors.white)
monitor.setCursorPos(1,1)
monitor.write("Cow Farm:")
monitor.CursorPos(20, 1)

if not cowenabled then
monitor.setTextColor(colors.red)
monitor.write("Inactive")
else
monitor.setTextColor(colors.green)
monitor.write("Active")

end

and so on so forth.
I'm curious again why my loop that puts this info on the screen for all spawners at once isn't good enough? :P It will be much smaller and a lot more flexible.

I'm glad that you accepted my bundled cable set and get function though. :P

#16 uh20

  • Members
  • 11 posts

Posted 01 February 2013 - 11:47 AM

oh sorry orwell, mornings and the brain was not up to remembering to look through all the posts. my bad
(no i was not trying to edit yours or something)

#17 ChunLing

  • Members
  • 2,027 posts

Posted 01 February 2013 - 11:55 AM

It may be that the table was the part Jinxtah had trouble understanding.

#18 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 01 February 2013 - 12:11 PM

View PostChunLing, on 01 February 2013 - 11:55 AM, said:

It may be that the table was the part Jinxtah had trouble understanding.
Maybe, indeed. But not explaining why you post the same deal with predefined variables will probably confuse him even more. :P It's of great importance to indicate why you do something in a certain way and how it works (at least in general). You, for example, do that very consistently. Not that it's a big deal, I just didn't agree with the model he used. :) This is certainly an example that calls for tables to stay at least a little manageable.

#19 ChunLing

  • Members
  • 2,027 posts

Posted 01 February 2013 - 04:58 PM

Well, it would also be up to Jinxtah to say which part was confusing anyway. But I occasionally amuse myself by throwing out charitable interpretations of things, just to show that I can (so people know that when I don't, I might be not doing so on purpose, to be evil :D ).

#20 Jinxtah

  • Members
  • 8 posts

Posted 10 February 2013 - 09:08 AM

I messed around with it some more, and just couldn't get it to work like I wanted.
I've cast myself upon the touch screen thing now. Even more complicated stuff, but it's all good.
Thanks for trying to help out everyone (especially Orwell).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users