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

Desktop error.

Started by raxteeze, 09 June 2015 - 05:34 PM
raxteeze #1
Posted 09 June 2015 - 07:34 PM
I created the operating system. If you are on the desktop, press Ctrl softkey, an error:

auth.eapp:173: attempt to compare nil with number

Desktop code:

http://pastebin.com/6VmYTv2E

Please, help!
Edited on 09 June 2015 - 05:51 PM
Creator #2
Posted 09 June 2015 - 07:43 PM
Please, please use pastebin, because this code is telling me nothing without line numbers
raxteeze #3
Posted 09 June 2015 - 07:51 PM
Please, please use pastebin, because this code is telling me nothing without line numbers
http://pastebin.com/6VmYTv2E
Creator #4
Posted 09 June 2015 - 07:58 PM
Thanks, I'll see if I can see what is wrong

Is the file on pastebin this file: auth.eapp?
raxteeze #5
Posted 09 June 2015 - 07:59 PM
Thanks, I'll see if I can see what is wrong

Is the file on pastebin this file: auth.eapp?
Yes :)/>
Creator #6
Posted 09 June 2015 - 08:00 PM
Everything seems allright. What I can tell you is that one of the Pos variable = nil.
KingofGamesYami #7
Posted 09 June 2015 - 08:04 PM

  local event, button, xPos, yPos = os.pullEvent("mouse_click")

  if xPos > 1 and xPos < 5 and yPos == 1 then --#line 173
  settings()
end

This line would error if a mouse_click event was generated without parameters, but this is (normally) impossible. A program or function could use os.queueEvent to produce such an error, but I don't see why one would.

Alternatively, if this line:

os.pullEvent = os.pullEventRaw

…was run at any point before, the event returned could be a 'terminate' event, which doesn't have parameters (eg. both xPos and yPos would be nil). A terminate event is fired when control + t is held down for an extended period of time.
raxteeze #8
Posted 09 June 2015 - 08:06 PM
Everything seems allright. What I can tell you is that one of the Pos variable = nil.
I know that. Therefore, the requested help. :)/>
Creator #9
Posted 09 June 2015 - 08:06 PM

  local event, button, xPos, yPos = os.pullEvent("mouse_click")

  if xPos > 1 and xPos < 5 and yPos == 1 then --#line 173
  settings()
end

This line would error if a mouse_click event was generated without parameters, but this is (normally) impossible. A program or function could use os.queueEvent to produce such an error, but I don't see why one would.

Alternatively, if this line:

os.pullEvent = os.pullEventRaw

…was run at any point before, the event returned could be a 'terminate' event, which doesn't have parameters (eg. both xPos and yPos would be nil). A terminate event is fired when control + t is held down for an extended period of time.

Yes, but there is the mouse_click filter
KingofGamesYami #10
Posted 09 June 2015 - 08:08 PM
Yes, but if os.pullEvent was set to os.pullEventRaw, terminate events could be returned. os.pullEvent normally filters terminate events and errors appropriately

from bios.lua

function os.pullEventRaw( sFilter )
    return coroutine.yield( sFilter )
end

function os.pullEvent( sFilter )
    local eventData = { os.pullEventRaw( sFilter ) }
    if eventData[1] == "terminate" then
        error( "Terminated", 0 )
    end
    return table.unpack( eventData )
end
Yevano #11
Posted 10 June 2015 - 07:27 AM
Yes, but if os.pullEvent was set to os.pullEventRaw, terminate events could be returned. os.pullEvent normally filters terminate events and errors appropriately

from bios.lua

function os.pullEventRaw( sFilter )
	return coroutine.yield( sFilter )
end

function os.pullEvent( sFilter )
	local eventData = { os.pullEventRaw( sFilter ) }
	if eventData[1] == "terminate" then
		error( "Terminated", 0 )
	end
	return table.unpack( eventData )
end

Not if a filter is given, which there is. That would only happen if no filter was given or if the filter was "terminate".

Are you perhaps running your program in a custom coroutine loop? It could be that you're passing the event data to the coroutines incorrectly, if that's the case. That's my best guess, as you shouldn't even be yielding to that call since the filter is mouse_click and you're pressing a key when the error occurs.
Bomb Bloke #12
Posted 10 June 2015 - 07:57 AM
Yes, but if os.pullEvent was set to os.pullEventRaw, terminate events could be returned. os.pullEvent normally filters terminate events and errors appropriately

Not if a filter is given, which there is. That would only happen if no filter was given or if the filter was "terminate".

What KoGY's (quite correctly) pointing out is that if you do:

os.pullEvent = os.pullEventRaw

… then terminate events will be returned by os.pullEvent() calls even if a filter is supplied, because that is the behaviour of os.pullEventRaw() / coroutine.yield().

If that were not the case, then it'd be impossible to terminate any script whilst it was using a filter.
Dragon53535 #13
Posted 11 June 2015 - 06:16 PM
There are two solutions for the problem, one is a do and forget, the other is a repeating do. First solution, the do and forget:
Override os.pullEvent at the top of the script to just ignore terminate events.

local oldPull = os.pullEvent --#Just for if when you DO close, you can reset os.pullEvent
os.pullEvent = function(sFilter)
  local eventData = { os.pullEventRaw( sFilter) }
  if eventData[1 == "terminate" then
    --#Do nothing!
  else
    return unpack(eventData)
  end
end

The second solution is to at every os,pullEvent call to check to make sure the event that you are sent, is the event you want.
The thing is, you'd have to do this every time you use os.pullEvent. Personally, I'd use the first suggestion

local event,param1,param2,param3 = os.pullEvent("mouse_click")
if event == "mouse_click" then
  --# Do the stuffs
end