SHOW:
|
|
- or go back to the newest paste.
| 1 | --Movement Program by Galygious | |
| 2 | --Variables | |
| 3 | local tArgs = { ... }
| |
| 4 | local dirlist = {'u','l','r'}
| |
| 5 | --Functions | |
| 6 | local printUsage = function(ecode) | |
| 7 | if ecode == 0 then | |
| 8 | print('Error Code 0\nThis program requires these variables:\narg1 - Direction (u,l,r)')
| |
| 9 | do return end | |
| 10 | elseif ecode == 1 then | |
| 11 | print('Error Code 1\nThis program requires these variables:\narg1 - Direction (u,l,r)')
| |
| 12 | do return end | |
| 13 | elseif ecode == 2 then | |
| 14 | print('Error Code 2\nThis program requires that variable one be a direction (u,l,r)')
| |
| 15 | do return end | |
| 16 | end | |
| 17 | end | |
| 18 | ||
| 19 | local turtleturn = function(Dir) | |
| 20 | if Dir == 'r' then | |
| 21 | turtle.turnRight() | |
| 22 | elseif Dir == 'l' then | |
| 23 | turtle.turnLeft() | |
| 24 | elseif Dir == 'u' then | |
| 25 | for i=1,2 do | |
| 26 | turtle.turnRight() | |
| 27 | end | |
| 28 | end | |
| 29 | end | |
| 30 | ||
| 31 | local hasval = function(tab,val) | |
| 32 | for i, value in ipairs(tab) do | |
| 33 | if value == val then | |
| 34 | return true | |
| 35 | end | |
| 36 | end | |
| 37 | return false | |
| 38 | end | |
| 39 | ||
| 40 | --Argument Handling | |
| 41 | if tArgs[1] ~= nil then | |
| 42 | if #tArgs ~= 1 then | |
| 43 | printUsage(1) | |
| 44 | elseif not hasval(dirlist, tArgs[1]) then | |
| 45 | printUsage(2) | |
| 46 | else | |
| 47 | local Dir = tArgs[1] | |
| 48 | turtleturn(Dir) | |
| 49 | return | |
| 50 | end | |
| 51 | else | |
| 52 | printUsage(0) | |
| 53 | end |