I have an error:
uos.lua:48: Expected string, string
But I have no idea while it is there??? :S it is coming from the following line:
local file = fs.open("startup", "w")
Anyone? :(/>
uos.lua:48: Expected string, string
local file = fs.open("startup", "w")
Post the whole code.
function boot() -- Finished
-- Checks whether advComputer or not
if term.isColour == false then
notColour()
end
print("Starting boot process...")
print(" ")
-- Checks for api
if fs.exists("uapi") == false then
print("> Downloading uAPI...")
downloadAPI()
end
-- Repeats a sleep until the API is downloaded
repeat
sleep(1)
until (fs.exists("uapi") == true)
os.loadAPI("uapi")
uapi.cs()
uapi.drawBox(1, 51, 1, 2, " ", "white", "cyan")
uapi.printC("uOS - Created By DannySMc", 1, false, "white", "cyan")
uapi.printC(">> Boot Sequence Log <<", 2, false, "white", "cyan")
term.setCursorPos(1,3)
print("> Checking for startup file...")
if fs.exists("startup") == false then
local file = fs.open("startup", "w")
file.writeLine("shell.run('uOperatingSystem')")
file.close()
sleep(1)
print("> Startup file created...")
else
print("> A Startup file was found")
end
print("> Setting some variables...")
intComputerID = os.computerID()
modemSide = nil
uOSVersion = 1
username = nil
password = nil
txtColour = "white"
bkgColour = "cyan"
print(" ")
sleep(1)
print("> Checking for modem...")
modemSide = uapi.findPeripheral("modem")
if not modemSide == nil then
print("> Modem Connected...")
rednet.open(modemSide)
else
print("> Modem Not Connected...")
end
print(" ")
sleep(1)
print("> Checking for disk drive...")
driveSide = uapi.findPeripheral("drive")
if not driveSide == nil then
print("> Disk Drive Drive Connected...")
else
print("> Disk Drive Not Connected...")
end
print(" ")
sleep(1)
print("> Checking for whatsnew feed...")
if fs.exists("whatsnew") == false then
print("> Updating whatsnew feed...")
getNews = http.get("https://raw.github.com/dannysmc95/uprograms/master/uOSUpdates")
getNews = getNews.readAll()
file = fs.open("whatsnew", "w")
file.write(getNews)
file.close()
print("> Feed updated...")
else
print("> Whatsnew feed is up-to-date...")
end
print(" ")
sleep(1)
print("> Checking for config file...")
if fs.exists(".uOSConfig") == false then
configWriter("firstInstall")
else
print("> Config file found, loading file...")
sleep(0.5)
OSConfig = uapi.loadConfig(".uOSConfig")
-- creates vars
username = OSConfig.user
password = OSConfig.pass
txtColour = OSConfig.txtColour
bkgColour = OSConfig.bkgColour
-- Finished
print("> Completed...")
end
print(" ")
print("> Checking for OS files...")
sleep(1)
if fs.exists("OSFiles") == false then
print("> OS Files need to be downloaded...")
print("> OS Files will now be downloaded...")
update("programs")
else
print("> OS Files are present...")
end
print(" ")
print("Boot Sequence Finished!!")
sleep(1.5)
homeScreen()
end
Post the whole code.
Here is the code for that function:function boot() -- Finished -- Checks whether advComputer or not if term.isColour == false then notColour() end print("Starting boot process...") print(" ") -- Checks for api if fs.exists("uapi") == false then print("> Downloading uAPI...") downloadAPI() end -- Repeats a sleep until the API is downloaded repeat sleep(1) until (fs.exists("uapi") == true) os.loadAPI("uapi") uapi.cs() uapi.drawBox(1, 51, 1, 2, " ", "white", "cyan") uapi.printC("uOS - Created By DannySMc", 1, false, "white", "cyan") uapi.printC(">> Boot Sequence Log <<", 2, false, "white", "cyan") term.setCursorPos(1,3) print("> Checking for startup file...") if fs.exists("startup") == false then local file = fs.open("startup", "w") file.writeLine("shell.run('uOperatingSystem')") file.close() sleep(1) print("> Startup file created...") else print("> A Startup file was found") end print("> Setting some variables...") intComputerID = os.computerID() modemSide = nil uOSVersion = 1 username = nil password = nil txtColour = "white" bkgColour = "cyan" print(" ") sleep(1) print("> Checking for modem...") modemSide = uapi.findPeripheral("modem") if not modemSide == nil then print("> Modem Connected...") rednet.open(modemSide) else print("> Modem Not Connected...") end print(" ") sleep(1) print("> Checking for disk drive...") driveSide = uapi.findPeripheral("drive") if not driveSide == nil then print("> Disk Drive Drive Connected...") else print("> Disk Drive Not Connected...") end print(" ") sleep(1) print("> Checking for whatsnew feed...") if fs.exists("whatsnew") == false then print("> Updating whatsnew feed...") getNews = http.get("https://raw.github.com/dannysmc95/uprograms/master/uOSUpdates") getNews = getNews.readAll() file = fs.open("whatsnew", "w") file.write(getNews) file.close() print("> Feed updated...") else print("> Whatsnew feed is up-to-date...") end print(" ") sleep(1) print("> Checking for config file...") if fs.exists(".uOSConfig") == false then configWriter("firstInstall") else print("> Config file found, loading file...") sleep(0.5) OSConfig = uapi.loadConfig(".uOSConfig") -- creates vars username = OSConfig.user password = OSConfig.pass txtColour = OSConfig.txtColour bkgColour = OSConfig.bkgColour -- Finished print("> Completed...") end print(" ") print("> Checking for OS files...") sleep(1) if fs.exists("OSFiles") == false then print("> OS Files need to be downloaded...") print("> OS Files will now be downloaded...") update("programs") else print("> OS Files are present...") end print(" ") print("Boot Sequence Finished!!") sleep(1.5) homeScreen() end
if fs.exists("HelloWorld") then -- If it's true
-- Do something
elseif not fs.exists("HelloWorld") then -- If it's not true, false
-- Do something else
end
if not modemSide == nil then
-- blah
end
Why don't you do this?
if modemSide ~= nil then
-- blah
end
Also, You can just do this when checking booleansif fs.exists("HelloWorld") then -- If it's true -- Do something elseif not fs.exists("HelloWorld") then -- If it's not true, false -- Do something else end
And saw you doing thisWhy don't you do this?if not modemSide == nil then -- blah end
if modemSide ~= nil then -- blah end
Edit: I can't see the error, It may be something that your API is causing, Post the code for that too if you want us to help you ;)/>
Also, 888:th post! :D/>
-- uOS -> Simplistic and productive operating system
-- Created By DannySMc
-- Version 1.0
-- Platform: Lua Virtual Machine
-- Error Codes: XX-XX-XXXXXX ( example: ( cw-e1-1state ) ) -> (cw: configWriter function) (e1: error code 1 (first in the function)) (1state: 1st if statement)
-- VARS
version = "1.0"
craftVer = os.version()
intW, intH = term.getSize()
-- VARS END
-- Security Method
oldEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
-- Program Starter
function boot() -- Finished
-- Checks whether advComputer or not
if term.isColour == false then
notColour()
end
print("Starting boot process...")
print(" ")
-- Checks for api
if fs.exists("uapi") == false then
print("> Downloading uAPI...")
downloadAPI()
end
-- Repeats a sleep until the API is downloaded
repeat
sleep(1)
until (fs.exists("uapi") == true)
os.loadAPI("uapi")
uapi.cs()
uapi.drawBox(1, 51, 1, 2, " ", "white", "cyan")
uapi.printC("uOS - Created By DannySMc", 1, false, "white", "cyan")
uapi.printC(">> Boot Sequence Log <<", 2, false, "white", "cyan")
term.setCursorPos(1,3)
print("> Checking for startup file...")
if fs.exists("startup") == false then
local file = fs.open("startup", "w")
file.writeLine("shell.run('uOperatingSystem')")
file.close()
sleep(1)
print("> Startup file created...")
else
print("> A Startup file was found")
end
print("> Setting some variables...")
intComputerID = os.computerID()
modemSide = nil
uOSVersion = 1
username = nil
password = nil
txtColour = "white"
bkgColour = "cyan"
print(" ")
sleep(1)
print("> Checking for modem...")
modemSide = uapi.findPeripheral("modem")
if not modemSide == nil then
print("> Modem Connected...")
rednet.open(modemSide)
else
print("> Modem Not Connected...")
end
print(" ")
sleep(1)
print("> Checking for disk drive...")
driveSide = uapi.findPeripheral("drive")
if not driveSide == nil then
print("> Disk Drive Drive Connected...")
else
print("> Disk Drive Not Connected...")
end
print(" ")
sleep(1)
print("> Checking for whatsnew feed...")
if fs.exists("whatsnew") == false then
print("> Updating whatsnew feed...")
getNews = http.get("https://raw.github.com/dannysmc95/uprograms/master/uOSUpdates")
getNews = getNews.readAll()
file = fs.open("whatsnew", "w")
file.write(getNews)
file.close()
print("> Feed updated...")
else
print("> Whatsnew feed is up-to-date...")
end
print(" ")
sleep(1)
print("> Checking for config file...")
if fs.exists(".uOSConfig") == false then
configWriter("firstInstall")
else
print("> Config file found, loading file...")
sleep(0.5)
OSConfig = uapi.loadConfig(".uOSConfig")
-- creates vars
username = OSConfig.user
password = OSConfig.pass
txtColour = OSConfig.txtColour
bkgColour = OSConfig.bkgColour
-- Finished
print("> Completed...")
end
print(" ")
print("> Checking for OS files...")
sleep(1)
if fs.exists("OSFiles") == false then
print("> OS Files need to be downloaded...")
print("> OS Files will now be downloaded...")
update("programs")
else
print("> OS Files are present...")
end
print(" ")
print("Boot Sequence Finished!!")
sleep(1.5)
login()
end
function downloadAPI() -- Finished
getGit = http.get("https://raw.github.com/dannysmc95/uprograms/master/uapi")
getGit = getGit.readAll()
file = fs.open("uapi", "w")
file.write(getGit)
file.close()
end
function notColour() -- Finished
term.clear()
term.setCursorPos(12,6)
print("|------------------------|")
term.setCursorPos(12,7)
print("| Apologies! :'( |")
term.setCursorPos(12,8)
print("| This was made for an |")
term.setCursorPos(12,9)
print("| advanced computer only |")
term.setCursorPos(12,10)
print("|------------------------|")
sleep(3)
os.shutdown()
end
function configWriter(configFile) -- Finished (FirstInstall / Settings)
if configFile then
sleep(0.5)
if configFile == "firstInstall" then
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", "white", "cyan")
uapi.printC("Config Writer -> First Install (Mode)", 1, false, "white", "cyan")
term.setCursorPos(1,2)
print(">What is your chosen username?")
write("Username: ")
strUsernameToConfig = tostring(read())
print(" ")
print(">What is your chosen password?")
write("Password: ")
strPasswordToEncrypt = tostring(read("*"))
strPasswordToConfig = uapi.encrypt(strPasswordToEncrypt, 6)
print(" ")
print(">What colour do you wish to make the text?")
write("Text Colour: ")
strTextColour = tostring(read())
print(" ")
print(">What background colour would you like to use?")
write("BkgColour: ")
strBackgroundColour = tostring(read())
print(" ")
print(">Creating config...")
sleep(0.5)
print(">Finished, rebooting...")
uapi.saveConfig({['user']=strUsernameToConfig, ['pass']=strPasswordToConfig, ['txtColour']=strTextColour, ['bkgColour']=strBackgroundColour}, ".uOSConfig")
sleep(1.5)
os.reboot()
elseif configFile == "settings" then
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", txtColour, bkgColour)
uapi.printC("Config Writer -> Settings", 1, false, txtColour, bkgColour)
term.setCursorPos(1,2)
print(">If you wish to keep the setting the")
print(" same then leave it blank")
print(" ")
sleep(1)
print(">What is your chosen username?")
write("Username: ")
strUsernameToConfig = tostring(read())
if strUsernameToConfig == nil then
strUsernameToConfig = username
end
print(" ")
print(">What is your chosen password?")
write("Password: ")
strPasswordToEncrypt = tostring(read("*"))
if strPasswordToEncrypt == nil then
strPasswordToEncrypt = password
else
strPasswordToConfig = uapi.encrypt(strPasswordToEncrypt, 6)
end
print(" ")
print(">What colour do you wish to make the text?")
write("Text Colour: ")
strTextColour = tostring(read())
if strTextColour == nil then
strTextColour = txtColour
end
print(" ")
print(">What background colour would you like to use?")
write("BkgColour: ")
strBackgroundColour = tostring(read())
if strBackgroundColour == nil then
strBackgroundColour = bkgColour
end
print(" ")
print(">Saving your settings...")
sleep(0.5)
uapi.saveConfig({['user']=strUsernameToConfig, ['pass']=strPasswordToConfig, ['txtColour']=strTextColour, ['bkgColour']=strBackgroundColour}, ".uOSConfig")
print(">Completed, returning home...")
sleep(0.5)
homeScreen()
end
else
uapi.drawBox(12, 39, 8, 1, " ", "white", "cyan")
uapi.printC("Error: cw-e1-1state", 8, false, "white", "cyan")
sleep(3)
homescreen()
end
end
function login() -- Finished
uapi.cs()
uapi.drawBox(1, 51, 2, 1, " ", txtColour, bkgColour)
uapi.printC("uOS -> Login Screen", 2, false, txtColour, bkgColour)
uapi.drawBox(6, 39, 7, 6, " ", txtColour, bkgColour)
term.setCursorPos(6,7)
print("Username: ")
term.setCursorPos(6,8)
print("---------------------------------------")
term.setCursorPos(6,10)
print("Password: ")
term.setCursorPos(6,11)
print("---------------------------------------")
term.setCursorPos(6,9)
write("> ")
strUserToCheck = tostring(read())
term.setCursorPos(6,12)
strPassToCheck = tostring(read("*"))
uapi.drawBox(1, 51, 16, 1, " ", txtColour, bkgColour)
uapi.printC(">> Checking Username and Password <<", 16, false, txtColour, bkgColour)
sleep(1)
if strUserToCheck == username then
strPasswordEncrypted = uapi.encrypt(strPassToCheck, 6)
if strPasswordEncrypted == password then
uapi.printC(">> Success, Logging you in, Please Wait <<", 16, false, txtColour, bkgColour)
sleep(2)
homeScreen()
else
uapi.printC(">> Error, Wrong Password, Rebooting <<", 16, false, txtColour, bkgColour)
sleep(2)
os.reboot()
end
else
uapi.printC(">> Wrong Username, Rebooting Terminal <<", 16, false, txtColour, bkgColour)
sleep(2)
os.reboot()
end
end
function update(updateType) -- done programs not full update
if updateType == "programs" then
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", false, txtColour, bkgColour)
uapi.printC("Update -> Type: Programs", 1, false, txtColour, bkgColour)
term.setCursorPos(1,2)
print("> Please wait as the programs are downloaded, this")
print("> could take a while depending on your internet")
print("> speed. Average time is normally: 30 seconds.")
print(" ")
print("> Starting download, please wait...")
term.setCursorPos(1,7)
write("> Downloading uShare...")
getGit = http.get("https://raw.github.com/dannysmc95/uprograms/master/ushare")
getGit = getGit.readAll()
file = fs.open("ushare", "w")
file.write(getGit)
file.close()
print("Complete")
term.setCursorPos(1,8)
write("> Downloading uRetrieve...")
getGit = http.get("https://raw.github.com/dannysmc95/uprograms/master/uretrieve")
getGit = getGit.readAll()
file = fs.open("uretrieve", "w")
file.write(getGit)
file.close()
print("Complete")
term.setCursorPos(1,9)
write("> Downloading uNotepad...")
getGit = http.get("https://raw.github.com/dannysmc95/uprograms/master/unotepad")
getGit = getGit.readAll()
file = fs.open("ushare", "w")
file.write(getGit)
file.close()
print("Complete")
term.setCursorPos(1,10)
write("> Downloading uChat...")
getGit = http.get("https://raw.github.com/dannysmc95/uprograms/master/uchat")
getGit = getGit.readAll()
file = fs.open("uchat", "w")
file.write(getGit)
file.close()
print("Complete")
term.setCursorPos(1,11)
file = fs.open("OSFiles", "w")
file.close()
print(" ")
print("> Programs are downloaded, rebootingg..")
sleep(1)
os.reboot()
elseif updateType == "full" then
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", false, txtColour, bkgColour)
uapi.printC("Update -> Type: Full", 1, false, txtColour, bkgColour)
end
end
function homeScreen() -- Finished
redMsgCount = 0
uapi.cs()
local feed = uapi.loadConfig("whatsnew")
-- Draw Instructions
uapi.drawBox(1, 51, 19, 1, " ", txtColour, bkgColour)
drawTime()
-- Draw time at bottom of screen
uapi.drawBox(1, 51, 18, 1, " ", txtColour, bkgColour)
uapi.printC("Rednet Messages Received: "..redMsgCount, 18, false, txtColour, bkgColour)
-- Create top banner
uapi.drawBox(1, 51, 1, 1, " ", txtColour, bkgColour)
uapi.printC("uOS -> Welcome "..username, 1, false, txtColour, bkgColour)
-- Draw options list
paintutils.drawLine(1,2,1,17,colours[bkgColour])
paintutils.drawLine(51,2,51,17,colours[bkgcolour])
uapi.printA("1. Main menu", 3, 3, false, txtColour, bkgColour)
uapi.printA("2. CraftOS Boot", 3, 5, false, txtColour, bkgColour)
-- Draw whastnew feed
-- FIX LATER
uapi.printA("Any bugs you may find, please report them!", 3, 15, false, txtColour, bkgColour)
if not modemSide == nil then -- Opens rednet
rednet.open(modemSide)
end
while true do -- Clock, Rednet, Char Events
local event, arg1, arg2, arg3, arg4, arg5 = os.pullEvent()
if event == "timer" and arg1 == timer then -- Timer Input
drawTime()
os.startTimer(1)
elseif event == "rednet" then -- Rednet messages
intSenderID = tostring(arg1)
strSerMessage = arg2
intDisTravelled = tostring(arg3)
strMessage = textutils.unserialize(strSerMessage)
if fs.exists("msgs/"..intSenderID) == true then -- deletes message from same sender if exists
fs.delete("msgs/"..intSenderID)
end
file = fs.open("msgs/"..intSenderID, "w")
file.writeLine("Sender ID: "..intSenderID)
file.writeLine("Distance: "..intDisTravelled.." blocks away")
file.write(strMessage)
file.close()
rednet.send(arg1, "Auto:R")
redMsgCount = tonumber(redMsgCount)
redMsgCount = redMsgCount + 1
redMsgCount = tostring(redMsgCount)
uapi.printC("Rednet Messages Received: "..redMsgCount, 18, false, txtColour, bkgColour)
elseif event == "char" then -- Actual User Input
if arg1 == "1" then
mainMenu()
elseif arg1 == "2" then
termBoot()
end
end
end
end
function drawTime() -- Finished
worldTime = textutils.formatTime(os.time())
worldDate = os.day()
uapi.printC("World Time: "..worldTime.." Day: "..worldDate, 19, false, txtColour, bkgColour)
end
function mainMenu()
-- Settings (TextColour, BackgroundColour, username, password)
-- uShare (Allows file sharing)
-- uChat (Chat program)
-- uRetrieve (Has updates for uOS and programs)
-- uAPI (Installed and loaded on boot)
-- uNotepad (Text editor for uOS)
-- Terminal Boot (Boots shellOS)
end
function termBoot() -- Finished
uapi.cs()
term.setTextColour(colours.lime)
print("> Booting terminal...")
print("> Please wait as uOS resets console defaults...")
sleep(1)
fs.delete("startup")
os.unloadAPI("uapi")
file = fs.open("startup", "w")
file.writeLine("shell.setAlias('uos', 'uOperatingSystem')")
file.close()
shell.setAlias("uos", "uOperatingSystem")
print("> Type 'uos' to restart computer in uOS")
print(" ")
print("> Rebooting in 2.5 seconds...")
sleep(2.5)
os.reboot()
end
function about() -- Finished
uapi.cs()
uapi.drawBox(1,51, 1, 1, " ", txtColour, bkgColour)
uapi.printC("Console Information", 1, false, txtColour, bkgColour)
term.setCursorPos(1,2)
print(">> Getting information... <<")
sleep(1.5)
print("> uOS Version: "..version)
print("> "..craftVer)
print("> Terminal Size - X: "..intW.." and Y: "..intH)
print("> Terminal Preferred - X: 51 and Y: 19")
print(" ")
print(">> Getting Compatible Programs Installed <<")
sleep(1.5)
if fs.exists("uShare") then
uShareExists = "Installed"
else
uShareExists = "Not Installed"
end
if fs.exists("uNotepad") then
uNotepadExists = "Installed"
else
uNotepadExists = "Not Installed"
end
if fs.exists("uRetrieve") then
uRetrieveExists = "Installed"
else
uRetrieveExists = "Not Installed"
end
if fs.exists("uChat") then
uChatExists = "Installed"
else
uChatExists = "Not Installed"
end
print(" ")
print("> uShare: "..uShareExists)
print("> uRetrieve: "..uRetrieveExists)
print("> uNotepad: "..uNotepadExists)
print("> uChat: "..uChatExists)
uapi.drawBox(1, 51, 19, 1, " ", txtColour, bkgColour)
uapi.printC("Press 1 to exit", 19, false, txtColour, bkgColour)
local event, aboutExit = os.pullEvent("char")
if aboutExit == "1" then
homescreen()
else
homescreen()
end
end
function credits() -- Finished
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", txtColour, bkgColour)
uapi.printC("uOS -> Credits", 1, false, txtColour, bkgColour)
term.setCursorPos(1,2)
print("> Created By DannySMc")
print("> Twitter: @dannysmc95")
print("> Github: http://github.com/dannysmc95/")
print("> Email: danny.smc95@gmail.com")
print(" ")
print("Quick word from Danny:")
print("Well first of all thanks for reading this, I really")
print("enjoyed making this and I hope you have as much fun")
print("using it. I just wanted something I could use on my")
print("server so people could make the most of CC while it")
print("was around. I built mainly to be used as a home pc.")
print("If there is anything you wish to be changed/added ")
print("then please tell me and I shall implement it, any ")
print("bugs then email me the problem, thanks! Enjoy!")
print(" ")
print(">> Press enter to return <<")
while true do
event, param1 = os.pullEvent("char")
if param1 == "enter" then
homeScreen()
end
end
end
function help()
-- Simple to use help menu with over 25 answers to console questions
-- GUI -> Using numbers 1 to 9
-- Programs help
-- error numbers
end
function uTurtle()
-- Allows turtle movement using rednet
end
function uLocate() -- Finished
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", txtColour, bkgColour)
uapi.printC("uLocate -> Global Positioning System", 1, false, txtColour, bkgColour)
term.setCursorPos(1,2)
print("> Options List:")
print("> 1. Receive GPS location of this computer")
print("> 2. Receive GPS location of a turtle")
print("> 3. Receive GPS location of a computer")
print("> 4. How it all works")
print("> 5. ComputerCraft/World Requirements")
print("> 6. Send GPS Hosting Program To Turtle")
print("> 7. Go to home screen")
print(" ")
print(">> Press the number of the chosen option <<")
while true do
local event, param1 = os.pullEvent("char")
if param1 == "1" then
intX, intY, intZ = gps.locate()
if not intX == nil then
term.setCursorPos(1, 13)
print("> This computers location:")
print("> X: "..intX.." Y: "..intY.." Z: "..intZ)
print("> Press enter to go back")
while true do
event, goBack = os.pullEvent("char")
if goBack == "enter" then
sleep(0.5)
uLocate()
end
end
else
term.setCursorPos(1,13)
print("> Failed to receive location...")
sleep(1)
uLocate()
end
elseif param1 == "2" then
term.setCursorPos(1,13)
print("> This is not implemented yet.")
elseif param1 == "3" then
term.setCursorPos(1,13)
print("> This is not implemented yet.")
elseif param1 == "4" then
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", txtColour, bkgColour)
uapi.printC("uLocate -> How it works", 1, false, txtColour, bkgColour)
term.setCursorPos(1,2)
print("The GPS is an API pre-installed with ComputerCraft ")
print("from V1.31. This API introduces a way of being able")
print("to find out your location using computers that host")
print("their own location, the computer trying to find its")
print("location will get the results from four computers ")
print("and using the modem distances (Rednet API) will try")
print("and calculate it's distance and then figure out its")
print("own location using X,Y,Z coordinates! Awesome huh??")
print("This is very useful for locating where turtles are!")
print(" ")
print(">> Press enter to go back <<")
while true do
event, goBack = os.pullEvent("char")
if goBack == "enter" then
sleep(0.5)
uLocate()
end
end
elseif param1 == "5" then
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", txtColour, bkgColour)
uapi.printC("uLocate -> World/Config Requirements", 1, false, txtColour, bkgColour)
term.setCursorPos(1,2)
print("uOS uses many kinds of config/world requirements!!!")
print("> ComputerCraft config needs to have the modems ")
print(" range changed to at least over 10 digits for long")
print(" range usage.")
print("> You need to have a hosting network on, this can ")
print(" be done using option 6 in the uLocate Menu.")
print("> A dimensional anchor or something to keep the gps")
print(" hosting computer loaded, otherwise it won't work.")
print(" ")
print(">> Press enter to go back <<")
while true do
event, goBack = os.pullEvent("char")
if goBack == "enter" then
sleep(0.5)
uLocate()
end
end
elseif param1 == "6" then
uapi.cs()
uapi.drawBox(1, 51, 1, 1, " ", txtColour, bkgColour)
uapi.printC("uShare -> Send GPS Host", 1, false, txtColour, bkgColour)
term.setCursorPos(1,2)
if modemSide == nil then
modemSide = uapi.findPeripheral("modem")
if modemSide == nil then
print("> Modem Wasn't Detected...")
sleep(1)
uLocate()
end
end
print("> Please note you will need uShare running in")
print(" receive mode!")
print(" ")
print("> What is the ID you wish to send it to?")
write("ID: ")
intIDToSend = tonumber(read())
print("> Finding file...")
if not fs.exists("gps_deploy") == true then
print("> File not downloaded, downloading...")
getPaste = http.get("http://pastebin.com/raw.php?i=qLthLak5")
getPaste = getPaste.readAll()
file = fs.open("gps_deploy", "w")
file.write(getPaste)
file.close()
else
print("> File found, sharing...")
end
rednet.open(modemSide)
file = fs.open("gps_deploy", "r")
fileToSer = file.readAll()
fileToSend = textutils.serialize(fileToSer)
rednet.send(intIDToSend, fileToSend)
sleep(1)
print("> File Sent!")
sleep(1)
uLocate()
elseif param1 == "7" then
homeScreen()
end
end
end
boot()
-- End Of Program
-- Written by DannySMc
-- Twitter: @dannysmc95
-- uAPI Version: 1.4
function getVer()
uVer = "1.4"
return uVer
end
-- Configuration File Protocols
function saveConfig(table, file)
fConfig = fs.open(file, "w") or error("Cannot open file "..file, 2)
fConfig.write(textutils.serialize(table))
fConfig.close()
end
function loadConfig(file)
fConfig = fs.open(file, "r")
ret = textutils.unserialize(fConfig.readAll())
return ret
end
-- Beaming Technology
function beam(username, xcord, ycord, zcord, blockSide)
command = peripheral.wrap(blockSide)
if command == "true" then
command.setCommand("/tp "..username.." "..xcord.." "..ycord.." "..zcord)
check = command.runCommand()
if check == "true" then
return true
else
return false
end
else
return "Syntax Error"
end
end
-- XP Functions
function xpGive(player, amount, blockSide)
if player and amount and blockSide then
command = peripheral.wrap(blockSide)
command.setCommand("/xp "..amount.." "..player)
check = command.runCommand()
if check == "true" then
return true
else
return false
end
else
return false
end
if not player then
return "Need player"
end
if not amount then
return "Need amount"
end
if not blockSide then
return "Need side of command block"
end
end
-- Peripheral Functions
function findPeripheral(Perihp) --Returns side of first matching peripheral matching passed string
for _,s in ipairs(rs.getSides()) do
if peripheral.isPresent(s) and peripheral.getType(s) == Perihp then
return s
end
end
return false
end
-- Common Draw Functions
function cs()
term.clear()
term.setCursorPos(1,1)
return
end
function setCol(textColour, backgroundColour)
if textColour and backgroundColour then
if term.isColour() then
term.setTextColour(colours[textColour])
term.setBackgroundColour(colours[backgroundColour])
return true
else
return false
end
else
return false
end
end
function resetCol()
if term.isColour then
term.setTextColour(colours.white)
term.setBackgroundColour(colours.black)
return true
else
return false
end
end
-- Print Functions
function printC(Text, Line, NextLine, Color, BkgColor) -- print centered
local x, y = term.getSize()
x = x/2 - #Text/2
term.setCursorPos(x, Line)
if Color then setCol(Color, BkgColor) end
term.write(Text)
if NextLine then
term.setCursorPos(1, NextLine)
end
if Color then resetCol(Color, BkgColor) end
return true
end
function printL(Text, Line, NextLine, Color, BkgColor) -- print line
local x, y = term.getSize()
if ((term.isColor) and (term.isColor() == false) and (Text == " ")) then Text = "-" end
for i = 1, x do
term.setCursorPos(i, Line)
if Color then setCol(Color, BkgColor) end
term.write(Text)
end
if NextLine then
term.setCursorPos(1, NextLine)
end
if Color then resetCol(Color, BkgColor) end
return true
end
function printA(Text, xx, yy, NextLine, Color, BkgColor) -- print anywhere
term.setCursorPos(xx,yy)
if Color then setCol(Color, BkgColor) end
term.write(Text)
if NextLine then
term.setCursorPos(1, NextLine)
end
if Color then resetCol(Color, BkgColor) end
return true
end
function clearLine(Line, NextLine) -- May seem a bit odd, but it may be usefull sometimes
local x, y = term.getSize()
for i = 1, x do
term.setCursorPos(i, Line)
term.write(" ")
end
if not NextLine then
x, y = term.getCursorPos()
term.setCursorPos(1, y+1)
end
return true
end
function drawBox(StartX, lengthX, StartY, lengthY, Text, Color, BkgColor) -- does what is says on the tin.
local x, y = term.getSize()
if Color then setCol(Color, BkgColor) end
if not Text then Text = "*" end
lengthX = lengthX - 1
lengthY = lengthY - 1
EndX = StartX + lengthX
EndY = StartY + lengthY
term.setCursorPos(StartX, StartY)
term.write(string.rep(Text, lengthX))
term.setCursorPos(StartX, EndY)
term.write(string.rep(Text, lengthX))
for i = StartY, EndY do
term.setCursorPos(StartX, i)
term.write(Text)
term.setCursorPos(EndX, i)
term.write(Text)
end
resetCol(Color, BkgColor)
return true
end
-- Download Functions
function getPBFile(PBCode, uPath) -- pastebin code of the file, and path to save
local PBFile = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(PBCode))
if PBFile then
local PBfileToWrite = PBfile.readAll()
PBfile.close()
local file = fs.open( uPath, "w" )
file.write(PBfileToWrite)
file.close()
return true
else
return false
end
end
-- Browser Functions
function webRequest(webAddress)
webFile = http.get("http://summotion.netai.net/uweb/"..textutils.urlEncode(webAddress)..".txt")
return webFile
end
function delWebDat()
if fs.exists("webDat") then
if fs.delete("webDat") == true then
return true
else
return "Delete Failed"
end
else
return false
end
end
-- Database Functions
db = {}
db.__index = db
function db.delete(Filename)
if fs.exists(Filename) then
fs.delete(Filename)
return true
end
return false
end
function db.load(Filename)
if not fs.exists(Filename) then
local F = fs.open(Filename, "w")
F.write("{}")
F.close()
end
local F = fs.open(Filename, "r")
local Data = F.readAll()
F.close()
Data = textutils.unserialize(Data)
return Data
end
function db.save(Filename, ATable)
local Data = textutils.serialize(ATable)
local F = fs.open(Filename, "w")
F.write(Data)
F.close()
return true
end
function db.search(searchstring, ATable)
for i, V in pairs(ATable) do
if tostring(ATable[i]) == tostring(searchstring) then
return i
end
end
return 0
end
function db.removeString(Filename, AString)
local TempT = db.load(Filename)
if type(TempT) ~= "table" then return false end
local Pos = db.search(AString, TempT)
if Pos > 0 then
table.remove(TempT, Pos)
db.save(Filename, TempT)
return true
else
return false
end
end
function db.insertString(Filename, AString)
local TempT = db.load(Filename)
if type(TempT) ~= "table" then TempT = {} end
table.insert(TempT, AString)
db.save(Filename, TempT)
return true
end
-- Encryption
function encrypt(Input, keyN) -- takes a string and returns an encrypted version, if keyN 1 - 9 returns encrypted string with solid number hash
local inType = type(Input)
local keystore = {}
local i = 1
local dec = ""
local key
if inType == "number" then
Input = tostring(Input)
end
repeat
if keyN then
key = keyN
else
key = math.random(9)
end
table.insert(keystore, key)
local tstr = string.char(Input:byte(i) + key)
dec = dec .. tstr
i = i + 1
until Input:byte(i) == nil
local cin = ""
for i = 1, #keystore do
cin = cin..keystore[i]
end
if keyN then
return dec
else
return dec, cin
end
end
function decrypt(Input, Hash, keyY) -- takes encrypted string with either hash (or solid hash if keyY is true) and converts it back to readable text
local keystore, tstr, i, dec
if keyY then
keystore = {Hash}
else
keystore = hashSplit(Hash)
end
i = 1
dec = ""
repeat
if keyY then
tstr = string.char(Input:byte(i) - keystore[1])
else
tstr = string.char(Input:byte(i) - keystore[i])
end
dec = dec .. tstr
i = i + 1
until Input:byte(i) == nil
return dec
end
function repCrypt(Input, numHash)
local keystore = {}
local i = 1
local dec = ""
local keyLength = #tostring(numHash)
numHash = tonumber(numHash)
local posCou = 1
repeat
if posCou > keyLength then posCou = 1 end
key = tonumber(string.sub(numHash, posCou, posCou))
posCou = posCou + 1
table.insert(keystore, key)
local tstr = string.char(Input:byte(i) - key)
dec = dec .. tstr
i = i + 1
until Input:byte(i) == nil
return dec
end
function repdeCrypt(Input, numHash)
local i = 1
local dec = ""
local keyLength = #tostring(numHash)
numHash = tonumber(numHash)
local posCou = 1
repeat
if posCou > keyLength then posCou = 1 end
key = tonumber(string.sub(numHash, posCou, posCou))
posCou = posCou + 1
tstr = string.sub(Input, i, i)
tstr = string.char(Input:byte(i) + key)
dec = dec .. tstr
i = i + 1
until Input:byte(i) == nil
return dec
end
-- Serial Generator
function serialGen(digits) -- seems to become unstable above 18 digits long
local serial
for i = 1, digits do
if i == 1 then
serial = math.random(9)
else
serial = serial.. math.random(9)
end
end
serial = tonumber(serial)
return serial
end
print("> Startup file created...")
Doubt that's the error line…~= means unequal, it's the same as "not ==" pretty much
A better solution though would simply be "if modemSide" which is the equivalent of "not modemSide == nil"
Anyways, this is line 48 nowDoubt that's the error line…print("> Startup file created...")
~= means unequal, it's the same as "not ==" pretty much
A better solution though would simply be "if modemSide" which is the equivalent of "not modemSide == nil"
Anyways, this is line 48 nowDoubt that's the error line…print("> Startup file created...")
the error comes from the fs part