View difference between Paste ID: Ujj4cFEt and TsgwW66G
SHOW: | | - or go back to the newest paste.
1
if not arg[1] then
2
    error("File not found.",2)
3
end
4
local file = io.open(arg[1], "r")
5
local map = textutils.unserialise(file:read("*a"))
6
file:close()
7
8
rednet.open("back")
9
10
print("Welcome to snap.")
11
print("To add new intersection stand in the middle and type name or leave blank and press enter.")
12
print("After adding new intersection you can add connections by typing index numbers of intersections to connect to. To leave connection mode type -1.")
13
print("To save and quit type \":q\".")
14
print("If you wish to abort saving just terminate the program.")
15
16
while true do
17
    local name
18
    local conn
19
    local x, z
20
    
21
    write("Name: ")
22
    name = read()
23
    x, _, z = gps.locate(2)
24
    if name == ":q" or x == nil then
25
        break
26
    elseif name == "" then
27
        name = nil
28
    end
29
    
30
    map.intersections[#map.intersections+1] = {x = x, y = z, name = name}
31
    print("Index: "..#map.intersections)
32
    while true do
33
        write("Connection: ")
34
        conn = tonumber(read())
35
        if conn == -1 then
36
            break
37
        end
38
        map.connections[#map.connections+1] = {#map.intersections, conn}
39
    end
40
end
41
file = io.open(arg[1],"w")
42
file:write(textutils.serialise(map))
43
file:close()
44