SHOW:
|
|
- or go back to the newest paste.
1 | -- Program made by AndySpam | |
2 | function split_string(str, pat) | |
3 | local t = {} | |
4 | local fpat = "(.-)"..pat | |
5 | local last_end = 1 | |
6 | local s, e, cap = str:find(fpat, 1) | |
7 | while s do | |
8 | if s ~= 1 or cap ~= "" then | |
9 | table.insert(t,cap) | |
10 | end | |
11 | last_end = e + 1 | |
12 | s, e, cap = str:find(fpat, last_end) | |
13 | end | |
14 | if last_end <= #str then | |
15 | cap = str:sub(last_end) table.insert(t, cap) | |
16 | end | |
17 | return t | |
18 | end | |
19 | function clear() | |
20 | term.clear() | |
21 | term.setCursorPos (1,1) | |
22 | end | |
23 | ||
24 | while true do | |
25 | clear() | |
26 | print ("Press any key to run.") | |
27 | local event, key = os.pullEvent ("char") | |
28 | clear() | |
29 | local source = http.get("http://example.com/turtle.txt") | |
30 | local aSource = source.readAll() | |
31 | source.close() | |
32 | local delay = 0.3 | |
33 | move = split_string(aSource, ",") | |
34 | ||
35 | for i=1, #move do | |
36 | if move[i] == "0" then | |
37 | turtle.forward() | |
38 | elseif move[i] == "1" then | |
39 | turtle.back() | |
40 | elseif move[i] == "2" then | |
41 | turtle.turnLeft() | |
42 | elseif move[i] == "3" then | |
43 | turtle.turnRight() | |
44 | elseif move[i] == "4" then | |
45 | turtle.up() | |
46 | elseif move[i] == "5" then | |
47 | turtle.down() | |
48 | elseif move[i] == "6" then | |
49 | turtle.dig() | |
50 | end | |
51 | sleep(delay) | |
52 | end | |
53 | sleep(1.5) | |
54 | end |