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

Cant Type?

Started by hbomb79, 23 July 2014 - 08:17 AM
hbomb79 #1
Posted 23 July 2014 - 10:17 AM
When i run the program below it seems to work okay, although i have so far found that if i do any of the following after the program has finished the PC shuts down:

- Terminate
- Press Enter
- Try To Run Another Program


I dont know why, although I dont run the loadA function then It doesnt crash ?!?!?!

So heres my question whats wrong with my code?

Code:


-- This script loads the APIs Required as well as checks for missing files and updates via GitHub
-- The Installer Will Check If The Computer is compatible
termX, termY = term.getSize()
function initBackground(color)
  term.setBackgroundColor(color)
  term.clear()
  drawTitleBar()
end
bootX = termX/2-7
bootY = termY/2-4
-- Loads All Boot Images
BL0 = paintutils.loadImage("systemFiles/BootLogos/boot0.nfp")
BL1 = paintutils.loadImage("systemFiles/BootLogos/boot1.nfp")
BL2 = paintutils.loadImage("systemFiles/BootLogos/boot2.nfp")
BL3 = paintutils.loadImage("systemFiles/BootLogos/boot3.nfp")
BL4 = paintutils.loadImage("systemFiles/BootLogos/boot4.nfp")
BL5 = paintutils.loadImage("systemFiles/BootLogos/boot5.nfp")
BL6 = paintutils.loadImage("systemFiles/BootLogos/boot6.nfp")
BL7 = paintutils.loadImage("systemFiles/BootLogos/boot7.nfp")
BL8 = paintutils.loadImage("systemFiles/BootLogos/boot8.nfp")
BLFinal = paintutils.loadImage('systemFiles/bootFail.nfp')
color = true

function bootLogo (state, x, y, bgcolor)
  if state == 0 then
	paintutils.drawImage(BL0, x, y)
  elseif state == 1 then
	paintutils.drawImage(BL1, x, y)
  elseif state == 2 then
	paintutils.drawImage(BL2, x, y)
  elseif state == 3 then
	paintutils.drawImage(BL3, x, y)
  elseif state == 4 then
	paintutils.drawImage(BL4, x, y)
  elseif state == 5 then
	paintutils.drawImage(BL5, x, y)
  elseif state == 6 then
	paintutils.drawImage(BL6, x, y)
  elseif state == 7 then
	paintutils.drawImage(BL7, x, y)
  elseif state == 8 then
	paintutils.drawImage(BL8, x, y)
  elseif state == 9 then
	paintutils.drawImage(BLFinal, x, y)
  end
  term.setBackgroundColor(bgcolor)
end

function PrintCentered(text, y)
local w, h = term.getSize()
	x = math.ceil(math.ceil((w / 2) - (#text / 2)), 0)+1
	term.setCursorPos(x, y)
term.clearLine()
	write(text)
end
function loadA()  --Auto Loads ALL APIs It Can As Long As They Are In /api
  drawTitleBar()
  local currentImage = -1
local total = #fs.list("/api")
term.setBackgroundColor(256)
term.setTextColor(1)
PrintCentered("Loading APIs", 4)
for _, fileApi in pairs(fs.list('/api')) do
  if string.sub(fileApi,1,1) ~= "." then
   if math.floor(_*(8/total)) ~= currentImage then
	currentImage = math.floor(_*(8/total))
	local image = paintutils.loadImage('systemFiles/BootLogos/boot'..currentImage..'.nfp')
	paintutils.drawImage(image, bootX, bootY)
   end
   if os.loadAPI('/api/'..fileApi) then
   sleep(0)
   term.setBackgroundColor(256)
   term.setTextColor(colors.white)
			term.setCursorPos(1,19)
   term.clearLine()
   term.setCursorPos(1,18)
   term.clearLine()
   PrintCentered(fileApi.." Loaded!", 18)
   sleep(1)
	  else
	 error ("Error Occurred Whilst Loading API: "..fileApi)
   end
  end
end
  PrintCentered ("Complete", 4)
  sleep(0)
  return true
end
function drawTitleBar()
  term.setBackgroundColor(128)
  term.setCursorPos(1,1)
  term.clearLine()
  term.setTextColor(colors.cyan)
  write "HbombOS Security Suite"
  term.setCursorPos(1,2)
  term.clearLine()
  term.setTextColor(256)
  write "Startup"
end
function main()
  term.setBackgroundColor(256)
  term.setTextColor(1)
  term.clear()
  bootLogo(1, bootX, bootY, 256)
  PrintCentered("Checking For Colour Support", 18)
-- if systemCheck.checkColor() then
  PrintCentered("Computer Supports Colour", 19)
-- end
  bootLogo(3, bootX, bootY, 256)
  sleep(0)
  bootLogo(4, bootX, bootY, 256)
  PrintCentered("Checking If Pocket", 18)
  sleep(0)
-- if systemCheck.checkPocket() then
  bootLogo(6, bootX, bootY, 256)
  PrintCentered("Computer Is Not Pocket", 19)
  --end
  sleep(0)
  bootLogo(7, bootX, bootY, 256)
  PrintCentered("Checking If Supports HTTP", 18)
  sleep(0.5)
  bootLogo(8, bootX, bootY, 256)
-- if systemCheck.checkhttp() then
  PrintCentered("System Check Complete!", 19)
-- end
  sleep(0)
  PrintCentered("Running Checks", 19)
  PrintCentered("Checking For Updates", 18)
  sleep(1)
  --if update.Check() then
   --[[ PrintCentered("An Update Has Been Detected", 19)
sleep(0)
	PrintCentered("Obtaining Latest Update From GitHub", 18)
PrintCentered("Seeking URL", 19)
sleep(1)
PrintCentered("Parsed", 19)
sleep(0)
PrintCentered("Downloading New Updater", 19)
--download.git("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Install/updater", "systemFiles/Install/updater")
sleep(0)
PrintCentered("Download Complete, Running Updater",18)
sleep(0)
shell.run("systemFiles/Install/updater")
  else]]--
	PrintCentered("You Are Running The Latest Version!", 19)
-- end
end
term.setBackgroundColor(256)
term.clear()
drawTitleBar()
--if loadA() then
  main()
--end

I included the entire thing incase its another function interfering or something…

Thanks In Advance
Edited on 23 July 2014 - 08:18 AM
hbomb79 #2
Posted 23 July 2014 - 10:37 AM
I appears that after commenting out the os.loadAPI and the if statement attached the system doesnt crash… Why is it crashing like this

EDIT: The APIs Are Loading… It least it says they are
Edited on 23 July 2014 - 08:39 AM
Bomb Bloke #3
Posted 23 July 2014 - 11:01 AM
If you're told the APIs are "being" loaded, then that means they crashed while loading and os.loadAPI() bugged out as a result. It'll refuse to attempt to load them again until the computer's rebooted, and there's nothing you can do to get around that - so, rig your APIs not to crash next time! ;)/>

It sounds a lot like at least one of your APIs is messing with os.pullEvent.
hbomb79 #4
Posted 23 July 2014 - 11:03 AM
Im not being told, just the message is saying the IF statement is returning true, although it still crashes, Ill check the APIs for any pull events

EDIT: None of the APIs Are Using the APIs, I used the installer you helped me with and wiped the PC and reinstalled and now its not having issues, maybe i edited something in an API before i changed them :/

EDIT 2: Now it is doing it again and i havent changed anything!
Edited on 23 July 2014 - 09:05 AM
hbomb79 #5
Posted 23 July 2014 - 11:09 AM
These are all my APIs:

print API:

function centered(text, y)
local w, h = term.getSize()
	x = math.ceil(math.ceil((w / 2) - (#text / 2)), 0)+1
	term.setCursorPos(x, y)
term.clearLine()
	write(text)
end

Update API:


function grabURL()
  url = "https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/version"
  return url
end
function Check()
for i=1, 3 do
  url = grabURL()
if url == nil then error "Update URL Is Nil, Please Report If It Isnt Your Fault!" end
  local response = http.get(url)
  if response then
	local data = response.readLine()
local f = fs.open("version", "r")
currentVersion = f.readLine()
f.close()
   if data ~= currentVersion then
	 return true
   else
	 return false
   end
  else
	error "The Update URL Cannot Be Resolved Or Is Missing [404]"
  end
end
error "The URL Cannot Be Reached! [208]"
end
function Update() --Updates The Updater Files
  for i=1, 3 do
	local response = http.get(updateURL)
   if response then
	 local data = response.readAll()
  local f = io.open("/systemFiles/Install/updater")
  f:write(data)
  f:close()
  return true
   else
	 error "UpdaterURL Could Not Be Resolved [404]"
  return false
   end
  end
error "The Updater Request Timed Out."
end

System Check API:


function checkColor()
  if not term.isColor then
	error "Computer Must Be Advanced, If It Is Then Report As A Bug"
  end
  return true
end
function checkPocket()
  if pocket then
	error "Software Does Not Support Pocket Computers"
  end
  return true
end
function checkhttp()
  if not http then
	error ("HTTP Must Be Enabled")
  end
  return true
end

Title Bar API:


function draw(text, subtext, textcolor, subtextcolor, backgroundcolor, defaultbgcolor, defaulttextcolor)
  if text == nil then text = "Nil" end
  if subtext == nil then subtext = "Nil" end
  if textcolor == nil then textcolor = colors.white end
  if subtextcolor == nil then subtextcolor = colors.cyan end
  if backgroundcolor == nil then backgroundcolor = 128 end
  if defaultbgcolor == nil then defaultbgcolor = 256 end
  if defaulttextcolor == nil then defaulttextcolor = 1 end
  term.setBackgroundColor(defaultbgcolor)
  term.clear()
  term.setBackgroundColor(backgroundcolor)
  term.setCursorPos(1,1)
  term.clearLine()
  term.setTextColor(textcolor)
  print(text)
  term.setCursorPos(1,2)
  term.clearLine()
  term.setTextColor(subtextcolor)
  print(subtext)
  term.setBackgroundColor(defaultbgcolor)
  term.setTextColor(defaulttextcolor)
end

download API:


-- Update URL, This is the URL the checker will use to obtain the Version File!
-- url = "https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/version"

function git(url, toPath) --Download From Git-hub To A PATH Specified in Arguments
for i=1, 3 do
sleep(0)
  local response = http.get(url)
  if response then
    local data = response.readAll()
if toPath then
   local file = io.open(toPath, "w")
   file:write(data)
   file:close()
   return true
else
   error "We Think The TOPATH Is Invalid!"
end
  else
    error "The URL Cannot Be Parsed [404]"
  end
end
error "An Error Occurred And The Request Timed Out [208]"
end

function update()
  git(url, toPath)
end


Any of them causing issues?
Edited on 23 July 2014 - 09:09 AM
hbomb79 #6
Posted 23 July 2014 - 11:18 AM
After looking around it seems Print, And TitleBar might be responsible as when there moved the system works again… What wrong with them, i have no idea

EDIT: Actually just print, Do i need to call it something else??

Well, so far it appears renaming 'print' to 'printer' appears to be a fix…. But i havent been able to test it properly yet
Edited on 23 July 2014 - 09:16 AM
Bomb Bloke #7
Posted 23 July 2014 - 11:25 AM
Loading an API called "print" will generate a table with said API's functions and stick the pointer to that table in the variable called "print". This variable usually holds a pointer to the "print" function, thus overwriting it breaks all the things. So, um, definitely don't do that.