Skip to content

Instantly share code, notes, and snippets.

@teodorlu
Created April 26, 2016 18:59
Show Gist options
  • Save teodorlu/a7f0f97480311ad05c597cb6cfbdd5f7 to your computer and use it in GitHub Desktop.
Save teodorlu/a7f0f97480311ad05c597cb6cfbdd5f7 to your computer and use it in GitHub Desktop.
-- Kjør på turtle
function main()
-- Hva sier pheripherals? Hvilken side er modemet på?
rednet.open("left")
while true do
sender, message = rednet.receive(99999)
print("Message from " .. sender .. " received: ")
print(message)
shell.run(unpack(message))
end
end
main()
-- File!
remoteId = 5
function toMoveCommand(keycode)
if keycode == keys.w then
return {"go", "forward"}
else
return nil
end
end
function remoteMove()
local action, keycode = os.pullEvent('key')
command = toMoveCommand(keycode)
if command == nil then
print("Unknown key: " .. keycode)
else
print("Sending ".. unpack(command))
rednet.send(remoteId, command)
end
end
function main( )
print("Listening for move commands ...")
rednet.open("back")
while true do
remoteMove()
end
end
main()
-- Starter jeg programmet sånn:
-- > ssh.lua 5
arguments = ...
-- ... blir arguments = "5"
remoteId = tonumber(arguments)
-- ... og remoteId = 5!
function pack(...)
return arg
end
function remoteCommand()
io.write("ssh@" .. remoteId .. "> ")
local intputString = io.read()
local commandTable = pack(intputString)
print("Sending: ")
print(unpack(commandTable))
rednet.send(remoteId, commandTable)
end
function main( )
print("Listening for move commands ...")
rednet.open("back")
while true do
remoteCommand()
end
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment