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

Error redstone.testBundledInput in function

Started by ernis1991, 15 October 2017 - 06:36 PM
ernis1991 #1
Posted 15 October 2017 - 08:36 PM
Hello,
I am new at programming and only today for the first time I tried functions. So I have a problem.
I written a function risc(side1,color1,side2,color2,credit_value)
and after I run program I get error: "expected string, number" on line "if redstone.testBundledInput(side1,color1) then" which is in function.
For example: redstone.testBundledInput("front",colors.white) works good, but in that case functions don't help me very much and then I must write long code repeating everything.
Whats the problem?

THIS is program:


local sidel	  = "left"
local sider	  = "right"
local sidet	  = "top"
local sidebo	 = "bottom"
local sideba	 = "back"
local sidef	  = "front"
local whitec	 = colors.white
local orangec	= colors.orange
local magentac   = colors.magenta
local lbluec	 = colors.lightBlue
local yellowc	= colors.yellow
local limec	  = colors.lime
local pinkc	  = colors.pink
local grayc	  = colors.gray

local lgrayc	 = colors.lightGray
local cyanc	  = colors.cyan
local purplec	= colors.purple
local bluec	  = colors.blue
local brownc	 = colors.brown
local greenc	 = colors.green
local redc	   = colors.red
local blackc	 = colors.black

local credit	 = 0
local modem = peripheral.wrap("bottom")
local m_bank_chs = 2
local m_bank_chr = 2

local function risc(side1,color1,side2,color2,credit_value)
	if redstone.testBundledInput(side1,color1) then
		credit = credit + credit_value
		modem.transmit(2,2,credit)
		peripheral.call("bottom","transmit",2,2, credit)
		redstone.setBundledOutput(side2,color2)
		credit = 0
		modem.transmit(2,2,credit)
		peripheral.call("bottom","transmit",2,2, credit)
	end
end

while true do
	risc("left",colors.white,"right",colors.white,1000000000)
	risc("left",colors.orange,"right",colors.orange,500000000)
	risc("left",colors.magenta,"right",colors.magenta,100000000)
	risc("left",colors.lightBlue,"right",colors.lightBlue,50000000)
	risc("left",colors.yellow,"right",colors.yellow,10000000)
	risc("left",colors.lime,"right",colors.lime,5000000)
	risc("left",colors.pink,"right",colors.pink,1000000)
	risc("left",colors.gray,"right",colors.gray,500000)
	risc("left",colors.lightGray,"right",colors.lightGray,100000)
	risc("left",colors.cyan,"right",colors.cyan,50000)
	risc("left",colors.purple,"right",colors.purple,10000)
	risc("left",colors.blue,"right",colors.blue,5000)
	risc("left",colors.brown,"right",colors.brown,1000)
	risc("left",colors.green,"right",colors.green,500)
	risc("left",colors.red,"right",colors.red,200)
	risc("left",colors.black,"right",colors.black,100)
	risc(sideba,whitec,sidet,whitec,50)
	risc(sideba,orangec,sidet,orangec,25)
	risc(sideba,magentac,sidet,magentac,10)
	risc(sideba,bluec,sidet,bluec,5)
	risc(sideba,lbluec,sidet,lbluec,2)
	risc(sideba,yellowc,sidet,yellowc,1)
	risc(sideba,limec,sidet,limec,0.5)
	risc(sideba,pinkc,sidet,pinkc,0.25)
	risc(sideba,greyc,sidet,greyc,0.1)
	risc(sideba,lgreyc,sidet,lgreyc,0.05)
	risc(sideba,cyanc,sidet,cyanc,0.02)
	risc(sideba,puplec,sidet,purple,0.01)

	sleep(1)

	redstone.setBundledOutput(sider,0)
	redstone.setBundledOutput(sidet,0)

end
Bomb Bloke #2
Posted 16 October 2017 - 04:02 AM
local grayc       = colors.gray

local lgrayc     = colors.lightGray
.
.
.
        risc(sideba,greyc,sidet,greyc,0.1)
        risc(sideba,lgreyc,sidet,lgreyc,0.05)
ernis1991 #3
Posted 17 October 2017 - 06:04 AM
Hello again,
Thank you for y our reply. I fixed what you pointed out. But still I have same error.
ernis1991 #4
Posted 17 October 2017 - 07:24 PM
So I found what the problems was. Thank you Hobbyist Coder for pointing my mistakes, that helped me to find another mistakes. I will BOLD my mistakes. So this is working code:


print("|------------------------------|")
print("|    PROGRAM RUNNING   |")
print("|------------------------------|")
local delay1	 = 0.4
local delay2	 = 0.4
local sidel	  = "left"
local sider	  = "right"
local sidet	  = "top"
local sidebo	 = "bottom"
local sideba	 = "back"
local sidef	  = "front"
[b]local whitec	 = 1   ----------- I used colors.white in this variable, but that seems not working, so I used numeric values of colors.
local orangec    = 2
local magentac   = 4
local lbluec	 = 8
local yellowc    = 16
local limec	  = 32
local pinkc	  = 64
local grayc	  = 128
local lgrayc	 = 256
local cyanc	  = 512
local purplec    = 1024
local bluec	  = 2048
local brownc	 = 4096
local greenc	 = 8192
local redc	   = 16384
local blackc	 = 32768[/b]
local credit	 = 0
local modem = peripheral.wrap("bottom")
local m_bank_chs = 2
local m_bank_chr = 2
local function risc(side,color,side2,color2,credit_value)
if redstone.testBundledInput(side,color) then
  credit = credit + credit_value 
  modem.transmit(2,2,credit)
  peripheral.call("bottom","transmit",2,2, credit)
  redstone.setBundledOutput(side2,color2)
  print("----/ credit to send /----")
  print("----/"    ..credit)
  print("----/ credit to send /----")
  credit = 0
  modem.transmit(2,2,credit)
  peripheral.call("bottom","transmit",2,2, credit)
  end
end
while true do
 [b] risc(sidel,whitec,sider,whitec,1000000000) ------------ For these lines I used  [i]risc("left",colors.white,"right",colors.white,1000000000) [/i]colors.white is wrong format.[/b]
[b]  risc(sidel,orangec,sider,orangec,500000000)
  risc(sidel,magentac,sider,magentac,100000000)
  risc(sidel,lbluec,sider,lbluec,50000000)
  risc(sidel,yellowc,sider,yellowc,10000000)
  risc(sidel,limec,sider,limec,5000000)
  risc(sidel,pinkc,sider,pinkc,1000000)
  risc(sidel,grayc,sider,grayc,500000)
  risc(sidel,lgrayc,siderc,lgray,100000)
  risc(sidel,cyanc,sider,cyanc,50000)
  risc(sidel,purplec,sider,purplec,10000)
  risc(sidel,bluec,sider,bluec,5000)
  risc(sidel,brownc,sider,brownc,1000)
  risc(sidel,greenc,sider,greenc,500)
  risc(sidel,redc,sider,redc,200)
  risc(sidel,blackc,sider,blackc,100)[/b]
  risc(sideba,whitec,sidet,whitec,50)
  risc(sideba,orangec,sidet,orangec,25)
  risc(sideba,magentac,sidet,magentac,10)
  risc(sideba,bluec,sidet,bluec,5)
  risc(sideba,lbluec,sidet,lbluec,2)
  risc(sideba,yellowc,sidet,yellowc,1)
  risc(sideba,limec,sidet,limec,0.5)
  risc(sideba,pinkc,sidet,pinkc,0.25)
  risc(sideba,grayc,sidet,grayc,0.1)
  risc(sideba,lgrayc,sidet,lgrayc,0.05)
  risc(sideba,cyanc,sidet,cyanc,0.02)
  risc(sideba,[b]purplec[/b],sidet,purplec,0.01)  ----- It was[b] [i]puplec [/i][/b]in code with mistakes
  
  sleep(delay1)
  redstone.setBundledOutput(sider,0)
  redstone.setBundledOutput(sidet,0)
  modem.transmit(2,2,credit)
  peripheral.call("bottom","transmit",2,2,credit)
  sleep(delay2)
end