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

Crashing program

Started by SNIPEZPUNISHER, 22 January 2014 - 08:30 AM
SNIPEZPUNISHER #1
Posted 22 January 2014 - 09:30 AM
So I'm working on a little bit of code but somehow it keeps crashing if you hit a key on your keyboard.
What i want my program to do is:
if you press OK then it will continue
So i got that part to work easily(not even a challenge)
But now i don't want it to crash if you press a key.

Here is the code i use:

while status=="notDone" do
local event, bottun, x, y = os.pullEventRaw()
if x>23 and x<26 and y==13 then --Coordinates
status="complete"
installationp1()
else
end
end

The error i get:
startup:45: attempt to compare nil with a number

Please help me because I need my programs set up in such a way that they don't crash and that nobody can look into the code.
Lyqyd #2
Posted 22 January 2014 - 10:15 AM
You need to check which event is coming in. That code assumes you're only going to get mouse_click events. You need to put that mouse_click event handling code in an if block that verifies that you have a mouse_click event.
Henness #3
Posted 22 January 2014 - 03:03 PM
Like Lydyd said you need to check if its a mouse click other wise its just going to check every event.


while true do
 local event, button, x, y = os.pullEventRaw()
 if event == "mouse_click" then
  if x>23 and x<26 and y==13 then
   -- code here
   break
  end
 end
end