--Test for Mob Only
chest = peripheral.wrap("container_chest_0")
for i=1, 27 do
data = chest.getStackInSlot(i)
print(data.captured)
return false, nil
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Chest Scanning Error / Safari Net Troubles
Started by cocotoffee, 21 April 2015 - 02:54 AMPosted 21 April 2015 - 04:54 AM
I'm trying to make my own code to automate a MFR Auto-Spawner. Currently I have a few things already set up, but I can't seem to get the data for whats in the safari net. I have the computer attached by a modem to a chest with various mobs in it. However, I set up a loop that only gives me the data on the 1st net. (1st slot) How do I make it scan ALL the slots/nets?
Edited on 22 April 2015 - 01:07 AM
Posted 21 April 2015 - 05:19 AM
Try removing the 'return false, nil' - that's most likely the problem
Posted 21 April 2015 - 10:59 AM
Sounds to me like you're using a peripheral proxy. Those things tend to break in weird and interesting ways if you break the block next to them (eg the chest) - try breaking and replacing the proxy itself.
Posted 22 April 2015 - 01:20 AM
Yup it was the return false part. Thank you for that, I just set the loop to stop at the last mob to stop another error, thank you!
Also, whenever there isn't a net in the chest it gives an error. Is there a way to just make it skip these parts and just continue on?
Also, whenever there isn't a net in the chest it gives an error. Is there a way to just make it skip these parts and just continue on?
Edited on 22 April 2015 - 12:54 AM
Posted 22 April 2015 - 04:52 AM
instead of this…
try this…
EDIT: Correction - thanks, BombBloke
print(data.captured)
try this…
if data then print(data.captured) end
EDIT: Correction - thanks, BombBloke
Edited on 22 April 2015 - 10:42 PM
Posted 22 April 2015 - 08:39 AM
Er, "if data then".
Posted 23 April 2015 - 12:37 AM
Thank you! I have expanded on the code and I'm trying to use the TouchPoint API (By Lyqyd) but I'm not understanding how to format the while true do… for when the button is clicked to activate the function. He has a sample of how to use it but I'm lost on the while true do part. I understand its what makes it so when you click it does something but how would I do that for my first button, Lights, to toggle the lights?
TouchPoint API Troubles:
My Code (Bottom) :
TouchPoint API Troubles:
Spoiler
--# load the touchpoint API
os.loadAPI("touchpoint")
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
--# add two buttons
t:add("left", nil, 2, 2, 14, 11, colors.red, colors.lime)
t:add("right", nil, 16, 2, 28, 11, colors.red, colors.lime)
--# draw the buttons
t:draw()
while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
--# p1 will be "left" or "right", since those are the button labels
--# toggle the button that was clicked.
t:toggleButton(p1)
--# and toggle the redstone output on that side.
rs.setOutput(p1, not rs.getOutput(p1))
end
end
My Code (Bottom) :
Spoiler
--AutoSpawner
--Random Stuff
os.loadAPI("touchpoint")
local t = touchpoint.new("RIGHT")
function set(var, val)
if type(val) == "string" then
_G[var] = val
end
end
--Variables
chest = peripheral.wrap("container_chest_0")
spawner = peripheral.wrap("auto_spawner_2")
monitor = peripheral.wrap("right")
local light, grinder = "0", "1"
--Buttons
t:add("Lights", function() toggleLights() end, 3, 3, 16, 5, colors.red, colors.lime)
--t:draw()
--Scan Mobs
local mobcheck -- available
for i = 1, 12 do
data = chest.getStackInSlot(i)
-- if data then print(data.captured) --Disabled for Testing
-- end
end
local selectedmob -- current to spawn
for i = 1, 1 do
mob = spawner.getStackInSlot(i)
-- if mob then print("Currently Selected: ",mob.captured,"s") --Disabled for Testing
-- end
end
--Redstone Toggle Functions
local function RedstoneOn(sSide, ...) -- on
local c = colors.combine(rs.getBundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
end
local function RedstoneOff(sSide, ...) -- off
local c= colors.combine(rs.getbundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
end
--Redstone Toggle Uses
local function LightsOn()
RedstoneOn("back", colors.yellow)
end
local function LightsOff()
RedstoneOff("back", colors.yellow)
end
local function AutoSpawnerOn()
RedstoneOn("back", colors.orange)
end
local function AutoSpawnerOff()
RedstoneOff("back", colors.orange)
end
local function toggleLights()
if lght == 0 then
LightsOn()
set("light", "1")
t:toggleButton("Lights")
elseif lght == 1 then
LightsOff()
set("light", "0")
t:toggleButton("Lights")
end
end
--Touchscreen
while true do
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then --Lost past here
end
Edited on 22 April 2015 - 10:39 PM
Posted 23 April 2015 - 12:55 AM
If you're just wanting to use the functions on the buttons, and no other event inputs, you can just use t:run() instead of an event handling loop.
Posted 23 April 2015 - 01:06 AM
Would I put the t:run() anywhere? Like next to the t:draw()? Or should it be somewhere more specific?
Posted 23 April 2015 - 01:19 AM
Instead of the while loop down at the bottom.
Of course, if you wanted to use any other events other than button presses, that won't be a viable option.
Of course, if you wanted to use any other events other than button presses, that won't be a viable option.
Posted 23 April 2015 - 11:30 PM
I added the t:run() part, but whenever I click the button it doesn't output the redstone signal to the yellow wire through the back. I just have a ProjectRed bundled cable on the back so it can send signals and I can do it manually through lua. The monitor is just on the right side but I can't seem to figure out why the button doesn't work. It doesn't even give an error so I must be missing something. Also have I set up toggleLights() function (near the bottom) correctly? It's my first time trying something like that.
Spoiler
--AutoSpawner
--Random Stuff
os.loadAPI("touchpoint")
local t = touchpoint.new("RIGHT")
function set(var, val)
if type(val) == "string" then
_G[var] = val
end
end
--Variables
chest = peripheral.wrap("container_chest_0")
spawner = peripheral.wrap("auto_spawner_2")
monitor = peripheral.wrap("right")
light = 0
--Buttons
t:add("Lights", function() toggleLights() end, 3, 3, 16, 5, colors.red, colors.lime)
t:draw()
--Scan Mobs
local mobcheck -- available
for i = 1, 12 do
data = chest.getStackInSlot(i)
-- if data then print(data.captured) --Disabled for Testing
-- end
end
local selectedmob -- current to spawn
for i = 1, 1 do
mob = spawner.getStackInSlot(i)
-- if mob then print("Currently Selected: ",mob.captured,"s") --Disabled for Testing
-- end
end
--Redstone Toggle Functions
local function RedstoneOn(sSide, ...) -- on
local c = colors.combine(rs.getBundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
end
local function RedstoneOff(sSide, ...) -- off
local c= colors.combine(rs.getbundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
end
--Redstone Toggle Uses
local function LightsOn()
RedstoneOn("back", colors.yellow)
end
local function LightsOff()
RedstoneOff("back", colors.yellow)
end
local function AutoSpawnerOn()
RedstoneOn("back", colors.orange)
end
local function AutoSpawnerOff()
RedstoneOff("back", colors.orange)
end
local function toggleLights()
if light == 0 then
LightsOn()
set("light", "1")
t:toggleButton("Lights")
elseif light == 1 then
LightsOff()
set("light", "0")
t:toggleButton("Lights")
end
end
--Start
t:run()
Posted 24 April 2015 - 01:03 AM
You need to add your button below the declaration for the toggleLights function, not above it.
Posted 24 April 2015 - 05:46 AM
So when ever you reference another function it should after it? And I changed the code to be in the correct order but it doesn't seem to work still. :(/>
Spoiler
--AutoSpawner
--Thank you everyone on the computercraft forumns
--Random Stuff
os.loadAPI("touchpoint")
local t = touchpoint.new("RIGHT")
function set(var, val)
if type(val) == "string" then
_G[var] = val
end
end
--Variables
chest = peripheral.wrap("container_chest_0")
spawner = peripheral.wrap("auto_spawner_2")
monitor = peripheral.wrap("right")
light = 0
--Scan Mobs
local mobcheck -- available
for i = 1, 12 do
data = chest.getStackInSlot(i)
-- if data then print(data.captured) --Disabled for Testing
-- end
end
local selectedmob -- current to spawn
for i = 1, 1 do
mob = spawner.getStackInSlot(i)
-- if mob then print("Currently Selected: ",mob.captured,"s") --Disabled for Testing
-- end
end
--Redstone Toggle Functions
local function RedstoneOn(sSide, ...) -- on
local c = colors.combine(rs.getBundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
end
local function RedstoneOff(sSide, ...) -- off
local c= colors.combine(rs.getbundledOutput(sSide), ...)
rs.setBundledOutput(sSide, c)
end
--Redstone Toggle Uses
local function LightsOn()
RedstoneOn("back", colors.yellow)
end
local function LightsOff()
RedstoneOff("back", colors.yellow)
end
local function AutoSpawnerOn()
RedstoneOn("back", colors.orange)
end
local function AutoSpawnerOff()
RedstoneOff("back", colors.orange)
end
--Button Functions
local function toggleLights()
if light == 0 then
LightsOn()
set("light", "1")
t:toggleButton("Lights")
elseif light == 1 then
LightsOff()
set("light", "0")
t:toggleButton("Lights")
end
end
--Buttons
t:add("Lights", function() toggleLights() end, 3, 3, 16, 5, colors.red, colors.lime)
t:draw()
t:run()
Posted 24 April 2015 - 03:26 PM
Well, the touchpoint.new call should be called with "right" instead of "RIGHT". You've also got colors.combine in both of your redstone functions, where the off function probably should have colors.subtract. You're also setting the global lights variable to the string "1" or "0" and then comparing it against the number 1 or 0, so you should use either numbers or strings in both places.