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

mob farm controller

Started by Crizzly23, 12 August 2015 - 06:40 PM
Crizzly23 #1
Posted 12 August 2015 - 08:40 PM
Im very new to computer craft and I wrote my first program yesterday. I have a mob farm and Im using the computer to switch between using the Killer Joe and the MFR grinder. When you open the computer, this is how it looks:
Spoiler
I then have a monitor to the left of it displaying the status of the grinder. My goal is to have something similar within the same computer to control what mobs I want to spawn. I could do this with redstone, but the problem is I only have 2 sides left on the computer for redstone and I plan on having around 5 different mobs. If anyone has any ideas on how to handle this please let me know, thanks!

Code I have written for it: http://pastebin.com/FxsSYycf

EDIT: I fixed the image.
Edited on 12 August 2015 - 08:05 PM
KingofGamesYami #2
Posted 12 August 2015 - 10:24 PM
You could use possibly use Project:Red cables. As an alternative, you could use another computer and use rednet to communicate which redstone outputs on that second computer you wish to use.
Crizzly23 #3
Posted 12 August 2015 - 10:53 PM
You could use possibly use Project:Red cables. As an alternative, you could use another computer and use rednet to communicate which redstone outputs on that second computer you wish to use.

I will try this thank you. How could have it so it displayed for example "5 = Turn Enderman On" then it would detect enderman was on and they were spawning it would change to "5 = Turn Enderman Off" and pressing the same key would disable it? Thanks for the help
Bomb Bloke #4
Posted 13 August 2015 - 02:04 AM
The idea is that you use "bundled" cables, specifically. If it's of any use to you, here's an example script.
Crizzly23 #5
Posted 13 August 2015 - 03:06 AM
Thanks for the help so far. What I want to do is when I press 5 it will go to another menu and display more options and I'm having trouble stopping the original program from looping when I press 5, and only have it loop if I press 1, 2, 3 or 4. Any help?
Bomb Bloke #6
Posted 13 August 2015 - 03:15 AM
Broadly speaking, you'd start another loop inside the first when the user hits 5. That way, the first loop can't repeat any more until the second one finishes.
Crizzly23 #7
Posted 13 August 2015 - 10:47 PM
Here is what I have so far. I'm using a second program, and when I press 5 and hit enter, it triggers the 2nd program to run. Probably not the best way to do it, but it was the easiest way for me.

First program: http://pastebin.com/befscBje

Second program: http://pastebin.com/iEqMuEYF

Enabling and disabling the enderman works fine.

Enabling and disabling the blaze works fine.

However, if I try to enable the blaze, while the enderman is already on, it shuts the enderman off. If I try to turn enderman on while blaze is on, they both get shut off.

How can I fix this? Thanks for the help
Bomb Bloke #8
Posted 14 August 2015 - 03:56 AM
Merge your current output with your new signal using rs.getBundledOutput() with colours.combine(). You'll likewise want to make use of colours.subtract() when shutting things down.
Crizzly23 #9
Posted 14 August 2015 - 08:47 PM
Im having a hard time getting this to work. Do you think you could write a few lines?
HPWebcamAble #10
Posted 14 August 2015 - 09:28 PM
Im having a hard time getting this to work. Do you think you could write a few lines?

I assume you are referring to 'colors.combine' / 'colors.subtract'

Here is a simple program that takes one argument.
If you give it ANYTHING as the first argument, it toggles the yellow output.
If you give it NOTHING, it toggles the black output.

local args = {...}

local side = "right" --# The side of the bundled cable
local currentOutput = rs.getBundledOutput(side)

if args[1] then --# We got the first argument, toggle yellow

  if colors.test( currentOutput , colors.yellow ) then --# is yellow already on?
	rs.setBundledOutput( side , colors.subtract(currentOutput , colors.yellow) )
  else --# Yellow wasn't on
	rs.setBundledOutput( side , colors.combine(currentOutput , colors.yellow) )
  end

else --# Didn't get the first arguemnt, toggle black

  if colors.test( currentOutput , colors.black ) then --# is black already on?
	rs.setBundledOutput( side , colors.subtract(currentOutput , colors.black) )
  else --# Black wasn't on
	rs.setBundledOutput( side , colors.combine(currentOutput , colors.black) )
  end

end
Edited on 14 August 2015 - 07:29 PM
flaghacker #11
Posted 14 August 2015 - 09:28 PM
Turning red on while keeping the current output would look something like this:

local side = "left"
local addColor = colors.red

rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), addColor))
The code does "get the current otput, add red to it and set it as the new output".

Turning red off is almost the same, just replace "colors.combine" with "colors.subtract". You can write a couple of functions to make it eaven easier:


function enableColor(side, color)
  rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
end

Again, with disableColor being the same with "subtract" instead of "combine".

edit: ninja'd
Edited on 14 August 2015 - 07:29 PM
Crizzly23 #12
Posted 15 August 2015 - 03:30 AM
Turning red on while keeping the current output would look something like this:

local side = "left"
local addColor = colors.red

rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), addColor))
The code does "get the current otput, add red to it and set it as the new output".

Turning red off is almost the same, just replace "colors.combine" with "colors.subtract". You can write a couple of functions to make it eaven easier:


function enableColor(side, color)
  rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
end

Again, with disableColor being the same with "subtract" instead of "combine".

edit: ninja'd

This has definitely been useful, but I'm having trouble getting this to work. I don't get an error or anything, it just doesn't output the signal. http://pastebin.com/T3irfAdw

Thanks for the help

EDIT: Ignore the code for the blaze. I want to get it working for the first mob (enderman) before I use the code for the others.
Edited on 15 August 2015 - 01:31 AM
Bomb Bloke #13
Posted 15 August 2015 - 03:42 AM
You've got to be careful where you put your brackets - for example, colors.combine(rs.getBundledOutput(side, addBrown)) should be colors.combine(rs.getBundledOutput(side), addBrown). You don't want to pass "addBrown" to the "getBundledOutput" function!

There's also a function definition in there that you never end up later calling, and things get even worse with the Blaze toggle.

Here's a fixed version:

Spoiler
local side = "top"

while true do
	term.clear()
	term.setCursorPos(1,1)
	
	print("Which mobs would you like to toggle?")
	print("1. Enderman")
	print("2. Blaze")
	print("B. Back")

	local input = io.read()

	if input == "1" then
		if rs.testBundledInput(side, colors.brown) then
			rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), colors.brown))
		else 
			rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), colors.brown))
		end
	elseif input == "2" then
		if rs.testBundledOutput(side, colors.green) then
			rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), colors.green))
		else
			rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), colors.green))
		end
	elseif input == "B" then
		term.clear()
		term.setCursorPos(1,1)
		break
	end
end
Crizzly23 #14
Posted 15 August 2015 - 04:03 AM
You've got to be careful where you put your brackets - for example, colors.combine(rs.getBundledOutput(side, addBrown)) should be colors.combine(rs.getBundledOutput(side), addBrown). You don't want to pass "addBrown" to the "getBundledOutput" function!

There's also a function definition in there that you never end up later calling, and things get even worse with the Blaze toggle.

Here's a fixed version:

Spoiler
local side = "top"

while true do
	term.clear()
	term.setCursorPos(1,1)
	
	print("Which mobs would you like to toggle?")
	print("1. Enderman")
	print("2. Blaze")
	print("B. Back")

	local input = io.read()

	if input == "1" then
		if rs.testBundledInput(side, colors.brown) then
			rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), colors.brown))
		else
			rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), colors.brown))
		end
	elseif input == "2" then
		if rs.testBundledOutput(side, colors.green) then
			rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), colors.green))
		else
			rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), colors.green))
		end
	elseif input == "B" then
		term.clear()
		term.setCursorPos(1,1)
		break
	end
end

This is really helpful, and I planned on fixing the blaze toggle once I got the enderman one to work. This code works fine turning them on, but it doesn't turn them off and I'm not sure how to fix it.
Bomb Bloke #15
Posted 15 August 2015 - 04:07 AM
Oops! Seems I didn't correct a "testBundledInput" there. Should both be using "testBundledOutput".
Crizzly23 #16
Posted 15 August 2015 - 04:17 AM
Do you mean rs.getBundledOutput (rs.testBundledOutput doesnt seem to be a thing)on lines 15 and 21? Changing those lines to that results in them not getting a signal.
Bomb Bloke #17
Posted 15 August 2015 - 02:55 PM
Ah, no testBundledOutput? My memory's clearly degrading, but that's still the gist of what you need to do: Check whether or not the colour is included in your current output. colours.test() will need to be used instead.

Eg:

if colours.test(rs.getBundledOutput(side), colors.brown) then
Crizzly23 #18
Posted 15 August 2015 - 06:48 PM
Am I doing something it wrong here? Enabling them works fine, but disabling them doesn't.

local side = "top"

while true do
		term.clear()
		term.setCursorPos(1,1)

		print("Which mobs would you like to toggle?")
		print("1. Enderman")
		print("2. Blaze")
		print("B. Back")

		local input = io.read()

		if input == "1" then
				if colors.test(rs.getBundledOutput(side),colors.brown) == true then
						rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), colors.brown))
				else
						rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), colors.brown))
				end
		elseif input == "2" then
				if colors.test(rs.getBundledOutput(side), colors.green) == true then
						rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), colors.green))
				else
						rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), colors.green))
				end
		elseif input == "B" then
				term.clear()
				term.setCursorPos(1,1)
				break
		end
end
Edited on 15 August 2015 - 04:50 PM
Bomb Bloke #19
Posted 16 August 2015 - 02:56 AM
Ah, that's right, colours.subtract() ended up broken in the latest ComputerCraft release… Give this a try:

http://www.computercraft.info/forums2/index.php?/topic/24056-touchpoint-api-total-lua-noob/