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

os.pullEvent() : sys.axs:292: attempt to compare nil with number [solved]

Started by Nothy, 21 May 2016 - 09:37 PM
Nothy #1
Posted 21 May 2016 - 11:37 PM
Yeah, this is really strange. Basically when I terminate my OS it throws this error: "sys.axs:292: attempt to compare nil with number".
On line 292 there's code that compares x and y coordinates of the last click.

	if x >= 20 and x <= 30 and y == 9 then
	  edge.render(20,9,30,9,colors.lightGray,colors.cyan,"",colors.gray)
	  term.setCursorPos(20,9)
	  term.setTextColor(colors.black)
	  term.setBackgroundColor(colors.lightGray)
	  usr = io.read()
	end
It does this in a while(true) loop, and it uses os.pullEvent

Here's my whackjob of a solution in a nutshell:


	local event, button, x, y = os.pullEvent("mouse_click")
	if event == "terminate" then
	  edge.log("Termination event caught!")
	  os.reboot()
	end
Edited on 21 May 2016 - 11:26 PM
Creator #2
Posted 21 May 2016 - 11:48 PM
That means that either x or y is nil. If you share some previous code, I might be more helpful. :)/>
Nothy #3
Posted 22 May 2016 - 12:27 AM
That means that either x or y is nil. If you share some previous code, I might be more helpful. :)/>
Sorry for the horribly delayed reply, here you go.


  while(true) do
    if settings.getVariable("os/settings.0","username") == "autoLogin" and settings.getVariable("os/settings.0","password") == "kernelSpecified-AutomaticLogin" then
	  parallel.waitForAny(main_gui,clock)
	  term.setBackgroundColor(colors.black)
	  shell.run("clear")
	  edge.render(16,7,34,12,colors.white,colors.cyan,"",colors.black,true)
	  --edge.render(17,8,34,8,colors.white,colors.cyan,"Welcome to AXIOM!",colors.black,false)
	  edge.render(17,9,34,9,colors.white,colors.cyan," (!) Fatal error",colors.red,false)
	  edge.render(16,10,34,10,colors.white,colors.cyan,"CODE: AXGUI-RUNTIME",colors.red,false)
	  tasks.kernel = false
	  tasks.permngr = false
	  tasks.clock = false
    end
    local event, button, x, y = os.pullEvent("mouse_click")
    if event == "terminate" then

    end
    if x == 18 and y == 7 then
	  os.shutdown()
    end
    if x >= 20 and x <= 30 and y == 9 then --#Error
	  edge.render(20,9,30,9,colors.lightGray,colors.cyan,"",colors.gray)
	  term.setCursorPos(20,9)
	  term.setTextColor(colors.black)
	  term.setBackgroundColor(colors.lightGray)
	  usr = io.read()
    end
Waitdev_ #4
Posted 22 May 2016 - 12:49 AM
Maybe try not having it a local variable?
Instead of:

local event,button,x,y = os.pullEvent("mouse_click")
do:

event,button,x,y = os.pullEvent("mouse_click")
Nothy #5
Posted 22 May 2016 - 12:52 AM
Maybe try not having it a local variable?
Instead of:

local event,button,x,y = os.pullEvent("mouse_click")
do:

event,button,x,y = os.pullEvent("mouse_click")
I tried that, and it didn't really seem to work that well. I think just simply handling a termination event should do the trick though. I'll tell you all how it goes. :D/>
Dragon53535 #6
Posted 22 May 2016 - 12:55 AM
A termination even will never even reach that point though. The internals of pullEvent catches a terminate event, and promptly terminates if one arises.

Even more so, don't remove the local, it makes your program run faster as it doesn't have to attempt to grab a variable defined in the global space. Analogy: Local, within arms reach. Global, I have to get out of my chair to get it.

As for your error, are you sure that this is the sys.axs file?

Edit: Holy crap, is your settings.getVariable function requiring you to open a file every time you want to check a setting? That's REALLY inefficient!
Edited on 21 May 2016 - 10:56 PM
Nothy #7
Posted 22 May 2016 - 01:04 AM
A termination even will never even reach that point though. The internals of pullEvent catches a terminate event, and promptly terminates if one arises.

Even more so, don't remove the local, it makes your program run faster as it doesn't have to attempt to grab a variable defined in the global space. Analogy: Local, within arms reach. Global, I have to get out of my chair to get it.

As for your error, are you sure that this is the sys.axs file?

Edit: Holy crap, is your settings.getVariable function requiring you to open a file every time you want to check a setting? That's REALLY inefficient!

I think I might have fixed the issue, and yes, it does open the file every time. It's an API my friend made in 2013. but it gets the job done!
Dragon53535 #8
Posted 22 May 2016 - 01:07 AM
Redesign it then, because that's a horrible thing to do if you're designing anything, much less an OS. What you would want to do is just load the settings into a variable, and then check them there. Your settings are never going to change unless you manually change them, and even then if that happens just re run the function that loaded them in the first place.
Nothy #9
Posted 22 May 2016 - 01:09 AM
Redesign it then, because that's a horrible thing to do if you're designing anything, much less an OS. What you would want to do is just load the settings into a variable, and then check them there. Your settings are never going to change unless you manually change them, and even then if that happens just re run the function that loaded them in the first place.
That's a very good idea. And I thought of doing that earlier today, since this inefficiency is certainly taking it's toll on the OS.