Jump to content




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


  • You cannot reply to this topic
8 replies to this topic

#1 Nothy

  • Members
  • 249 posts
  • LocationMars

Posted 21 May 2016 - 10: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 by Nothy, 22 May 2016 - 12:26 AM.


#2 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 21 May 2016 - 10:48 PM

That means that either x or y is nil. If you share some previous code, I might be more helpful. :)

#3 Nothy

  • Members
  • 249 posts
  • LocationMars

Posted 21 May 2016 - 11:27 PM

View PostCreator, on 21 May 2016 - 10:48 PM, said:

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


#4 Waitdev_

  • Members
  • 432 posts
  • LocationAdelaide

Posted 21 May 2016 - 11:49 PM

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")


#5 Nothy

  • Members
  • 249 posts
  • LocationMars

Posted 21 May 2016 - 11:52 PM

View PostWaitdev_, on 21 May 2016 - 11:49 PM, said:

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

#6 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 21 May 2016 - 11:55 PM

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 by Dragon53535, 21 May 2016 - 11:56 PM.


#7 Nothy

  • Members
  • 249 posts
  • LocationMars

Posted 22 May 2016 - 12:04 AM

View PostDragon53535, on 21 May 2016 - 11:55 PM, said:

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!

#8 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 22 May 2016 - 12: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.

#9 Nothy

  • Members
  • 249 posts
  • LocationMars

Posted 22 May 2016 - 12:09 AM

View PostDragon53535, on 22 May 2016 - 12:07 AM, said:

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.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users