Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --dofile("lib\\textutils.lua")
- --dofile("lib\\tableIO.lua")
- require("lib\\tableIO")
- local ex = nil
- local exArg = {}
- local data = tableIO.load("hm.data")
- function readNumber(min,max)
- local inp
- while type(inp) ~= "number" or (math.ceil(inp)~=inp or inp < min or inp>max) do
- inp = tonumber(io.read())
- end
- return inp
- end
- function listStrings(person)
- for i,v in pairs(data.people[person].strings) do
- print(i .. " - \""..v.text.."\"".. " (P:"..v.priority..")")
- end
- end
- function addString(person)
- print("Person: " .. person)
- print("")
- print("Add string:")
- local inp
- while type(inp) ~= "string" do
- inp = io.read()
- end
- table.insert(data.people[person].strings,{text=inp,priority=(#data.people[person].strings+1)})
- ex = updateStrings
- end
- function swapStrings(person)
- print("Person: " .. person)
- print("")
- listStrings(person)
- print("")
- print("Input String #1 (0 to cancel)")
- local s1 = readNumber(0,#data.people[person].strings)
- if s1 == 0 then
- ex = updateStrings
- return
- end
- print("Input String #2 (0 to cancel)")
- local s2 = readNumber(0,#data.people[person].strings)
- if s2 == 0 or s1 == s2 then
- ex = updateStrings
- return
- end
- local strings = data.people[person].strings
- local temp = strings[s1].priority
- strings[s1].priority = strings[s2].priority
- strings[s2].priority = temp
- ex = updateStrings
- end
- function updateStrings(person)
- print("Person: ".. person)
- print("")
- listStrings(person)
- print("\n1 - Add string\n2 - Delete string\n3 - Swap strings\n4 - back")
- local inp = readNumber(1,3)
- if inp == 1 then
- ex = addString
- elseif inp == 2 then
- ex = delString
- elseif inp == 3 then
- if #data.people[person].strings > 1 then
- ex = swapStrings
- end
- elseif inp == 4 then
- exArg = {}
- ex = personMenu
- end
- end
- function delString(person)
- print("Person: " .. person)
- print("")
- listStrings(person)
- print("")
- print("Delete which string? (0 to cancel)")
- local n = readNumber(0,#data.people[person].strings)
- if n ~= 0 then
- local sPriority = data.people[person].strings[n].priority
- table.remove(data.people[person].strings,n)
- for i,v in ipairs(data.people[person].strings) do
- if v.priority > sPriority then
- v.priority = v.priority-1
- end
- end
- end
- ex = updateStrings
- end
- function personMenu()
- print("\n\nWhich person?")
- local person
- while data.people[person] == nil and person ~= "back" do
- person = io.read():lower()
- end
- if person == "back" then
- exArg = {}
- ex = main
- return
- end
- print("Do what?\n1 - update strings\n2 - update gifts\n")
- local inp = readNumber(1,2)
- exArg = {person}
- if inp == 1 then
- ex = updateStrings
- elseif inp == 2 then
- ex = updateGifts
- end
- end
- function clear()
- os.execute("cls")
- end
- function main()
- clear()
- print("Do what?\n\n1 - person\n2 - gift\n")
- local inp = readNumber(1,2)
- if inp == 1 then
- ex = personMenu
- else
- ex = giftMenu
- end
- end
- ex = main
- while true do
- clear()
- ex(unpack(exArg))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement