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

Error when trying to pass variables to rs.testBundledInput

Started by recanem, 07 February 2014 - 10:34 AM
recanem #1
Posted 07 February 2014 - 11:34 AM
All - I'm trying to use variables for rs.testBundledInput and rs.setBundledOutput but get an error with the color name variable. I believe the error is in how I'm passing the color name variable, I've tested by explicitly stating a side and not the color (e.g. rs.testBundledInput("right",colors.checkColor) and will get the error. Then by explicitly stating the color and not the side (e.g. rs.testBundledInput(checkSide, colors.white) ) What I'm looking for help with is how to pass the actual color name to this code and not get an error. Please note I've identified the two lines of code where the error occurs with a comment for ease in finding it for this discussion. Note: I've tried searching for posts on "color variable testBundledInput" ,but that word is blocked in search so I'm not exactly sure what to use for a search term if a post like this already exists Thanks in advance for any help you could provide!

Error Message: mobSpawnerV2:18: Expected string, number



local monitor = peripheral.wrap("top")
local signalResult
local spawnTimer  =  30
local killTimer = 100
local inputTable =	  {}
--PopulateTable		
inputTable[1] = {"Mob Essence", "Slimes", "right", white, "back", white }	
inputTable[2] = {"Raw Beef, Leather", "Cows", "right", magenta, "back", magenta }
inputTable[3] = {"Glass Bottles, Glowstone Dust. Gunpowder, Redstone ,Spider Eyes, Sticks, Sugar", "Witches", "right", orange, "back", orange }
								
--Check for requested items, signals are sent via rednet cable on specific colors and computer sides (16 color inputs per computer side)
-- Once
function signalTest (tableKey)
	 local checkSide = inputTable[tableKey][3]
	 local checkColor = inputTable[tableKey][4]
		signalResult = rs.testBundledInput(checkSide,colors.checkColor) -- ERROR HERE trying to pass varialble containing color name
end
--Send Signal to Spawn requested Mob and kill it for item drops
function signalSend (side, color)
	 local sendSide = inputTable[tableKey][5]
	 local sendColor = inputTable[tableKey][6]
	 rs.setBundledOutput(sendSide, colors.sendColor) -- ERROR HERE trying to pass varialble containing color name
	 sleep(spawnTimer)
	 rs.setBundledInput(side, 0)
	 sleep(killTimer)
end
--write out to monitor what the system is working on (fancy stuff later)
function displayStatus (mobName, itemName)
	 local mobName = inputTable[tableKey][2]
	 local itemName = inputTable[tableKey][1]
	 monitor.clear()
	 monitor.setCursorPos(1,1)
	 monitor.write("Need Items: "..itemName)
	 monitor.setCursorPos(2,1)
	 monitor.write("Spawing Mobs: "..mobName)
	 monitor.setCursorPos(3,1)
	 monitor.write("Spawn Timer: "..spawnTimer)
	 monitor.setCursorPos(4,1)
	 monitor.write("Kill Timer: "..killTimer)
end
while true do
	 signalResult = false
	 for i=1 , #inputTable do
		  signalTest(i)
		  if signalResult == true then
			   displayStatus(i)
			   signalSend (i)
			   break -- breaks the for loop and starts over at 1
		  end
		  sleep(1)
	 end
end



Thanks,
Recanem
Lyqyd #2
Posted 07 February 2014 - 02:50 PM
You should just put colors.orange in the tables above and not try to index them later. If you really, really wanted to do it, you'd have to change your input tables to use the color names as strings, and then do colors[inputTable[tableKey][6]] in the bundled calls.

Essentially though, the easiest way to do it is to make it look like this, putting the actual color values in the table and indexing them directly:


inputTable[1] = {"Mob Essence", "Slimes", "right", colors.white, "back", colors.white }
...
signalResult = rs.testBundledInput(inputTable[tableKey][5], inputTable[tableKey][6])

Also, instead of setting the signalResult variable, you should just have the function return the value. Or better yet, just put the testBundledInput call in your if statement below and get rid of the whole function. :P/>
recanem #3
Posted 07 February 2014 - 03:45 PM
You should just put colors.orange in the tables above and not try to index them later. If you really, really wanted to do it, you'd have to change your input tables to use the color names as strings, and then do colors[inputTable[tableKey][6]] in the bundled calls.

Essentially though, the easiest way to do it is to make it look like this, putting the actual color values in the table and indexing them directly:


inputTable[1] = {"Mob Essence", "Slimes", "right", colors.white, "back", colors.white }
...
signalResult = rs.testBundledInput(inputTable[tableKey][5], inputTable[tableKey][6])

Also, instead of setting the signalResult variable, you should just have the function return the value. Or better yet, just put the testBundledInput call in your if statement below and get rid of the whole function. :P/>

@Lyqyd - Thank you! the colors.white in the table itself did the trick. I've also taken your advice and eliminated the function entirely, it made complete sense once I though about it, I was really checking for true anyhow.

Thanks,
Recanem