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:
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:I appreciate it's probably not the best way of doing things… but I'm still learning… ;)/>
>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()