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

[LUA][API][SOLVED]TBM Controller

Started by Lost Ninja, 20 January 2013 - 08:08 PM
Lost Ninja #1
Posted 20 January 2013 - 09:08 PM
Trying to control a RedPower built TBM with a computer, when I try and pass variables into redstone.setBundledOutput() I get errors "expected string, int". When I manually print out the variable I get the stored variable plus a number 1:
>redside = "left"
>print(redside)
"left"
1

Why do I get the number? And how can I remove it so my functions only receive the value I want them to receive?

In case it's a deeper issue with the program I've spoilered it below:
Spoiler
--[[
A program for controlling a TBM
This TBM has an Up/Down osccillating head
all code by LN :)/>/>/>
mk I
--]]

-- variables
-- input
inSide = "top"
wrk = redstone.getInput(inSide)

-- output
redSide = "left"

-- wires
fwdWire = "colors.white"
hUpWire = "colors.orange"
hDwnWire = "colors.magenta"
topFill = "colors.lightBlue"

-- movements
upCycle = 4 -- should be double what the actual movement is to allow for mis timed movemnets
dwnCycle = 4

-- general
moves = 0 -- shows how far it has moved since boot (want to make this a global but dunno how yet)
dbg = 0

-- functions
function output(msg)
	term.clear()
	term.setCursorPos(1,1)
	print(textutils.formatTime(os.time(), boolean))
	print(msg)
end

function motor(dir, count, wait)
	for n = 1,count do
		redstone.setBundledOutput(redSide, dir)
		sleep(0.5)
		redstone.setBundledOutput(redSide, 0)
		sleep(0.5)
		if dbg == 1 then
			print("Motor: " .. dir .. " had a signal sent.")
		end
		sleep(wait)
	end
end

function forward()
	motor(fwdWire,1,10)
end

function hUp()
	motor(hUpWire,upCycle,6)
end

function hDwn()
	motor(hDwnWire,dwnCycle,6)
end

function fillTop()
	motor(topFill,2,3)
end

function work()
	if wrk == true then
		hDwn()  -- makes sure head is in the bottom position prior to program start
	else
		output("Make sure lever is in on position and restart.")
		return
	end
	while wrk == true do
		forward()
		hUp()
		fillTop()
		hDwn()
		moves = moves + 1
		output("TBM has moved: " .. moves .. " since it last started moving.")
	end
	output("Job done with "..moves.." made since launch.")
end

work()
I appreciate it's probably not the best way of doing things… but I'm still learning… ;)/>
theoriginalbit #2
Posted 20 January 2013 - 09:09 PM

fwdWire = "colors.white"
hUpWire = "colors.orange"
hDwnWire = "colors.magenta"
topFill = "colors.lightBlue"
should be

fwdWire = colors.white
hUpWire = colors.orange
hDwnWire = colors.magenta
topFill = colors.lightBlue
The colours api will return a number for those variables… and thats what the redstone API wants. A number, not a string…
Lost Ninja #3
Posted 20 January 2013 - 09:37 PM
Okay, great that works a treat, I figured it'd be something stupid like that… :/

I was trying to apply the rules I learned to work with on the redSide variable (ie in inverted commas) to all variables…

Thanks muchly. :)/>
theoriginalbit #4
Posted 20 January 2013 - 09:38 PM
yeh using the quotes makes it a string… in this case you don't want a string…
no problems…