I am trying to create an music-system using a computer, a turtle and rednet.
I made some code, but it doesn't seem to work:
computer:
Spoiler
function clear()
term.clear()
term.setCursorPos( 1, 1 )
end
function disc()
print("witch disc do you want to hear? (1~16)")
local m = read()
end
function broadcast()
term.clear()
rednet.open("back")
rednet.broadcast(m)
end
function done()
message = rednet.receive()
if message == done then
sleep(240)
shell.run(startup)
end
end
while true do
clear()
disc()
broadcast()
done()
end
turtle:
Spoiler
function receive()
rednet.open("right")
local msg = rednet.receive()
term.write(msg)
end
function select()
if msg == "1" then
turtle.select(1)
elseif msg == "2" then
turtle.select(2)
elseif msg == "3" then
turtle.select(3)
elseif msg == "4" then
turtle.select(4)
elseif msg == "5" then
turtle.select(5)
elseif msg == "6" then
turtle.select(6)
elseif msg == "7" then
turtle.select(7)
elseif msg == "8" then
turtle.select(8)
elseif msg == "9" then
turtle.select(9)
elseif msg == "10" then
turtle.select(10)
elseif msg == "11" then
turtle.select(11)
elseif msg == "12" then
turtle.select(12)
elseif msg == "13" then
turtle.select(13)
elseif msg == "14" then
turtle.select(14)
elseif msg == "15" then
turtle.select(15)
else
turtle.select(16)
end
turtle.dropUp()
redstone.setOutput("top", true)
sleep(1)
redstone.setOutput("top", false)
end
function done()
turtle.suckUp()
rednet.send(6, "done")
end
while true do
turtle.select(1)
receive()
select()
done()
sleep(2)
shell.run("startup")
end
What I am trying to do is the following:
When you enter a number (1~16) on the computer, it sends it to the turtle. The turtle should read the message, and select the right slot.
It currently only selects slot 16, because the message send is 6.0. It doesn't matter what you type into the computer, the received message is always 6.0.
What is wrong?
Thank you for your time :)/>