Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Movement Program by Galygious
- --Variables
- local tArgs = { ... }
- local dirlist = {'u','l','r'}
- --Functions
- local printUsage = function(ecode)
- if ecode == 0 then
- print('Error Code 0\nThis program requires these variables:\narg1 - Direction (u,l,r)')
- do return end
- elseif ecode == 1 then
- print('Error Code 1\nThis program requires these variables:\narg1 - Direction (u,l,r)')
- do return end
- elseif ecode == 2 then
- print('Error Code 2\nThis program requires that variable one be a direction (u,l,r)')
- do return end
- end
- end
- local turtleturn = function(Dir)
- if Dir == 'r' then
- turtle.turnRight()
- elseif Dir == 'l' then
- turtle.turnLeft()
- elseif Dir == 'u' then
- for i=1,2 do
- turtle.turnRight()
- end
- end
- end
- local hasval = function(tab,val)
- for i, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- --Argument Handling
- if tArgs[1] ~= nil then
- if #tArgs ~= 1 then
- printUsage(1)
- elseif not hasval(dirlist, tArgs[1]) then
- printUsage(2)
- else
- local Dir = tArgs[1]
- turtleturn(Dir)
- return
- end
- else
- printUsage(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment