This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mr_Programmer's profile picture

[PROBLEM SOLVED] disk.isPresent cancel program

Started by Mr_Programmer, 06 September 2015 - 03:02 PM
Mr_Programmer #1
Posted 06 September 2015 - 05:02 PM
Hello,

I am currently working on a security system that controls all doors, power, machines and chest in the base, i only started yesterday on this code.

I am not a noob at coding as i have a decent knowlegde of coding and have been doing it for 3 years however when i am trying to see if the disk is present to get the boolen, it stops the program, its like when the computer receives the boolen it doesnt do anything with it but stop the program.

Please if your going to help, change my code and repost it in a comment!!!

I have checked the code several times and changed it in places several times.

Code Here: Dont worry it is spaced out correctly but for some reason it doesnt copy over the indentations when post thread *or i dont know how to :)/>*


--APIs

cPrint = function(y,tcol,txt)
local w,h = term.getSize()
term.setCursorPos(math.floor(w-#txt)/2,y)
term.setTextColour(tcol)
print(txt)
end

cPrintMultiCol = function(y,tcol,txt,tcol2,txt2)
local w,h = term.getSize()
term.setCursorPos(math.floor(w-#txt)/2,y)
term.setTextColour(tcol)
print(txt)
end

cPrintButton = function(y,tcol,bcol,txt)
local w,h = term.getSize()
term.setCursorPos(math.floor(w-#txt)/2,y)
term.setTextColour(tcol)
term.setBackgroundColour(bcol)
print(txt)
end

--Servers

rednet.open("back")
Server_Main = 3

--Random Variables
CardNotPresent = true
PgrmName = "Quarantine_Security_System "
IDReader = "bottom"

--Colours

c_header = 16
c_error = 128
c_writing = 512
c_black = 32768
c_red = 16384
c_white = 1
c_green = 32

--Code

function int()
term.clear()
term.setCursorPos(1,1)
term.setBackgroundColour(c_error)
term.clearLine()
term.setCursorPos(1,1)
term.setTextColour(c_header)
print(PgrmName.. version)
term.setCursorPos(1,2)
term.setBackgroundColour(c_black)
end

function loginIn()
term.setBackgroundColour(c_black)
cPrint(4, c_writing, "**Please Insert Your ID Card Bellow**")
cPrint(6, c_writing, "**Then Press The Button Bellow Once ID Card**")
cPrint(7, c_writing, "**Is In Place**")
cPrintButton(12, c_white, c_red, "/------------------\\")
cPrintButton(13, c_white, c_red, "|  Verify ID Card  |")
cPrintButton(14, c_white, c_red, "\\------------------/")

VerifyPage = true
while VerifyPage == true do
local event, button, X, Y = os.pullEventRaw()
if event == "mouse_click" then
if X >=15 and X <=34 and Y >=12 and Y <=14 and button == 1 then
present = disk.isPresent(IDReader)
if present == true then
CardNotPresent = false
checkIDCard()
else
term.setBackgroundColour(c_black)
term.clear()
int()
cPrint(4, c_red, "**You Have Not Inserted A ID Card**")
cPrint(5, c_red, "**Please Insert A ID Card And Try Again**")
cPrint(12, c_writing, "Returning To Verify Page In: 5 Seconds")
sleep(1)
cPrint(12, c_writing, "Returning To Verify Page In: 4 Seconds")
sleep(1)
cPrint(12, c_writing, "Returning To Verify Page In: 3 Seconds")
sleep(1)
cPrint(12, c_writing, "Returning To Verify Page In: 2 Seconds")
sleep(1)
cPrint(12, c_writing, "Returning To Verify Page In: 1 Seconds")
sleep(1)
cPrint(12, c_writing, "Returning To Verify Page In: 0 Seconds")
sleep(1)
term.clear()
int()
loginIn()
end
else
loginIn()
end
end
end
end

function checkIDCard()
if CardNotPresent == false then
rejectedPGRM = fs.exsists("disk/startup")
if rejectedPGRM == true then
delete("disk/startup")
else

end
end
end

Please Help, Thanks!!

This is what happends when i have pressed the verify button and the card is in the disk drive!
Edited on 06 September 2015 - 05:01 PM
KingofGamesYami #2
Posted 06 September 2015 - 05:26 PM
Your progaram is erroring, but because the background color is red, you cannot read the error.

I'd imagine it's erroring because 'delete' isn't a function…

Also: Did you know there's a table of colors? For example, instead of using c_black you can use colors.black.
Mr_Programmer #3
Posted 06 September 2015 - 06:17 PM
Your progaram is erroring, but because the background color is red, you cannot read the error.

I'd imagine it's erroring because 'delete' isn't a function…

Also: Did you know there's a table of colors? For example, instead of using c_black you can use colors.black.

Ohhhh OMG why did i not think of that :L and yes i am aware there is a table colours how ever i dont normally do "c_black" they are normally titled "c_writing" things like that, then when the program is finished they will be moved it a config file and edited from the GUI.