Posted 20 July 2015 - 02:28 AM
Hi All! I made myself a few functions that I always seem to be using, and put them into a program that I am using as an API. My own computer that I made the API on will work, however any other computers will draw errors from it; "attempt to index nil ?" Run it and see for your self
Program Code:
"API" Code:
Anyone know whats up and how to fix it? Thanks!
Program Code:
Spoiler
--------------------------------------------------
--API Load--
file = fs.exists("themccm")
if file == false then
fs.makeDir("themccm")
end
file = fs.exists("themccm/API")
if file == false then
shell.run("pastebin", "get", "5ww6Pb8i", "themccm/API")
end
os.unloadAPI("themccm/API")
os.loadAPI("themccm/API")
--------------------------------------------------
--Color Loading--
file = fs.exists("themccm/enderdice")
if file == false then
fs.makeDir("themccm/enderdice")
end
file = fs.exists("themccm/enderdice/textcolor")
if file == false then
colorfile = fs.open("themccm/enderdice/textcolor", "w")
colorfile.writeLine("red")
colorfile.close()
end
colorfile = fs.open("themccm/enderdice/textcolor", "r")
textcolor = colorfile.readLine()
colorfile.close()
--------------------------------------------------
--Functions--
function introPrint()
print[[
Enter 'help' For A List Of Commands
What Dice Do You Want To Roll? -In Numbers-]]
term.write("Roll A d")
end
--------------------------------------------------
--Clear--
clear()
--------------------------------------------------
--Visuals--
term.setTextColor(colors.lime)
print[[
--------------------------------------------------]]
term.setTextColor(colors.purple)
print[[
---- ----
/ 20 \ -------------------- / 20 \
\ 20 / /Welcome To EnderDice\ \ 20 /
---- |For Your Dicey Needs| ----
---- \ Made By: theMCcm / ----
/ 10 \ -------------------- / 10 \
\ 10 / \ 10 /
---- Beta V1.1 ----]]
term.setTextColor(colors.lime)
print[[
--------------------------------------------------]]
if colors[textcolor] then
term.setTextColor(colors[textcolor])
end
introPrint()
--------------------------------------------------
--Main Code--
while true do
input = read()
inp = tonumber(input)
if type(inp) == "number" then
if inp < 1 then
term.clearLine()
print("Sorry, But Dice Need To Be Atleast One-Sided!")
elseif inp > 100000000000 then
term.clearLine()
print("That Would Crash The Program! Try A Smaller Number")
else
dice = math.random(input)
term.clearLine()
print("You Rolled A d"..inp.." And Got "..dice)
end
lineUp()
lineUp()
term.clearLine()
term.write("Roll A d")
else
if input == "exit" or input == "Exit" or input == "E" or input == "e" or input == "EXIT" then
clear()
break
elseif input == "help" or input == "h" or input == "Help" or input == "H" or input == "HELP" then
lineUp()
term.clearLine()
term.write("Roll A d")
lineDown()
lineDown()
print[[
Type 'Exit' To Exit (Duh :P/>)
Type 'Color' To Change Text Color]]
lineUp()
lineUp()
lineUp()
lineUp()
term.write("Roll A d")
elseif input == "color" or input == "c" or input == "Color" or input == "C" or input == "COLOR" then
lineUp()
term.clearLine()
term.write("Pick A Color: ")
textcolor = read()
if colors[textcolor] then
term.setTextColor(colors[textcolor])
colorfile = fs.open("themccm/enderdice/textcolor", "w")
colorfile.writeLine("colors."..textcolor)
end
term.clearLine()
lineDown()
term.clearLine()
lineDown()
term.clearLine()
lineUp()
lineUp()
lineUp()
term.clearLine()
lineUp()
term.clearLine()
lineUp()
term.clearLine()
introPrint()
else
lineUp()
term.clearLine()
term.write("Roll A d")
lineDown()
term.clearLine()
print("That Wasnt A Number! Try Again.")
lineUp()
lineUp()
term.write("Roll A d")
end
end
end
--------------------------------------------------
--Extras--
--Pastebin: www.pastebin.com/KXRzGDcC
--CompCraft Forums:
---http://www.computercraft.info/forums2/index.php?/topic/24031-enderdice/
--Thanks All And Hope You Enjoy My Dice Roller!
--------------------------------------------------
Spoiler
--theMCcm's API--
function clear()
term.clear()
term.setCursorPos(1,1)
end
function lineUp()
x,y = term.getCursorPos()
y = y - 1
term.setCursorPos(1, y)
end
function lineDown()
x,y = term.getCursorPos()
y = y + 1
term.setCursorPos(1, y)
end
function lineClear()
term.clearLine()
end
Anyone know whats up and how to fix it? Thanks!