Jump to content




Program Goes Black then Reboots PC

lua computer

4 replies to this topic

#1 Eagle4Life69

  • Members
  • 13 posts

Posted 20 September 2012 - 03:35 PM

Hello pros, My program was running fine with tekkit 3.1.1 but now with 3.1.2 it reboots the PC the program is setup to get a signal from 3 different Item detectors one detectors counts blocks of 64 then 10 then 1. This is part of a banking program. Here is my code (i removed the URL to my site)

debug_char = "="
disk.eject("bottom")
term.clear()
term.setCursorPos(1,1)
function PrintCentered(sText)
	local w, h = term.getSize()
	local x, y = term.getCursorPos()
	x = math.max(math.floor((w / 2) - (#sText / 2)), 0)
y = math.max(math.floor((h / 2)),0)
	term.setCursorPos(x, y)
	print(sText)
end
coin = 0
bOut = 0
mult = 0
mult2 = 0
coin2 = 0
coin3 = 0
function counting()
rsInput = rs.getBundledInput("back")
  os.startTimer(20)
if colors.test(rsInput, colors.brown) == true then
  coin = coin + 1
elseif colors.test(rsInput, colors.purple) == true then
  coin2 = coin2 + 1
elseif colors.test(rsInput, colors.green) == true then
  coin3 = coin3 + 1
end
end
function loop()
while true do
  --event = os.pullEvent()
  if event == "redstone" then
   bOut = colors.combine(bOut, colors.white)
   rs.setBundledOutput("back", bOut)
   counting()
  elseif event == "timer" then
   bOut = colors.subtract(bOut, colors.yellow)
   rs.setBundledOutput("back", bOut)
   mult=coin*64
   mult2=coin2*10
   mult=coin3+mult+mult2
   sleep(10)
   break
  end
end
end
PrintCentered("Please Insert Debit Card")
function mainLoop()
while(true) do
  event, driveSide = os.pullEventRaw()
  if(event=="disk" and driveSide) then
   path = disk.getMountPath(driveSide)
   if(path) then
	path = path.."/id"
	file = fs.exists(path) and io.open(path, "r") or nil
   end
  
   term.clear()
   term.setCursorPos(1,1)
   PrintCentered("Please Enter Account Pin Number")
   pin = read("*")
  
	sCode = file:read()
	local response = http.get(
	  "/bank.php?task=check&id="..textutils.urlEncode( sCode ).."&pin="..textutils.urlEncode( pin )
	 )
	if response then
	local sResponse = response.readAll()
	 response.close()
	 if sResponse == "deny" then
	  term.clear()
	  term.setCursorPos(1,1)
	  print("Account or Password is wrong, Please try again")
	  disk.eject(driveSide)
	  sleep(5)
	  if(file) then file:close() file = nil end
	  os.reboot()
	 else
	  term.clear()
	  term.setCursorPos(1,1)
	  PrintCentered("Please Deposit Money into Chest on Right")
	  bOut = colors.subtract(bOut, colors.white)
	  rs.setBundledOutput("back", bOut)
	  sleep(8)
	  bOut = colors.combine(bOut, colors.white)
	  rs.setBundledOutput("back", bOut)
	  disk.eject(driveSide)
	  term.clear()
	  term.setCursorPos(1,1)
	   bOut = colors.combine(bOut, colors.yellow)
	   rs.setBundledOutput("back", bOut)
	   PrintCentered("Counting Money, This takes 20 seconds")
	  loop()
	  term.clear()
	  term.setCursorPos(1,1)
	   PrintCentered("You have Deposited $"..mult)
	  local response = http.get(
	  "/bank.php?task=deposit&id="..textutils.urlEncode( sCode ).."&pin="..textutils.urlEncode( pin ).."&amount="..textutils.urlEncode( mult )
	 )
	  if response then
	  sleep(3)
	   local sResponse1 = response.readAll()
	   term.clear()
	   term.setCursorPos(1,1)
	   PrintCentered("Your Current Balance is $"..sResponse1)
	   sleep(5)
	   if(file) then file:close() file = nil end
	   os.reboot()
	  
	  end
	 end
	end	  
	if(file) then file:close() file = nil end
  
  elseif(debug_char and event=="char" and driveSide==debug_char) then return("break") end
end
end
repeat
ok, err, val = pcall(mainLoop)
if(not ok and err) then
  if(err=="Terminated") then print ("Access denied.")
  else
   print(err)
  end
end
until(ok and err=="break")
It is failing as it should be counting the $$, I have been thrown a error once in a while something like vb issue not sure the exact code.

Thanks for any help you can give me.

#2 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 20 September 2012 - 06:33 PM

Please cut out the place in the code, where you think that the program is crashing, and then post that. Noone wants to look through all of this code, just to find one error, if they are not the author of the code, and are not depending on the code to work.

#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 20 September 2012 - 06:37 PM

 mad, on 20 September 2012 - 06:33 PM, said:

Please cut out the place in the code, where you think that the program is crashing, and then post that. Noone wants to look through all of this code, just to find one error, if they are not the author of the code, and are not depending on the code to work.
I disagree. I've been working on this on my breaks at work. I have not found the issue or solution yet, but I am still working on it. Most times, unless you know exactly where the error is, which in this case is not possible, you COULD post just the problem code. However, since it is not throwing an error, we need the whole picture to figure out what's wrong.

#4 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 20 September 2012 - 06:47 PM

I do see a few os.reboot() commands, but unfortunately, without having access to Minecraft or an emulator, I can't reproduce the error. I believe if you comment out the os.reboot() commands, and add error("Error name") in there. that way, you can debug where the program is causing you problems.

#5 Eagle4Life69

  • Members
  • 13 posts

Posted 20 September 2012 - 07:39 PM

I will remove the os.reboots to see the error.... And if I knew where the code has having problems I could fix... thanks for your help





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users