Jump to content




os.PullEvent error

lua

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

#1 RoD

  • Members
  • 313 posts

Posted 30 March 2014 - 01:21 AM

Hi everyone,
i am trying to prevent users to ctrl+t my program and i already done the:
Spoiler
And when i try to ctrl+t to test it it says:

184:attempt to compare nil with number

Here's the code i am working on:
Spoiler
Any ideas of what the problem is?

Edited by Rodmastercraft, 30 March 2014 - 08:10 AM.


#2 CometWolf

  • Members
  • 1,283 posts

Posted 30 March 2014 - 01:48 AM

Seeing as this is line 184
		   term.setBackgroundColor(colors.orange)
Im guessing this program isn't the problem. Please post the program included in the error message.

#3 RoD

  • Members
  • 313 posts

Posted 30 March 2014 - 08:10 AM

View PostCometWolf, on 30 March 2014 - 01:48 AM, said:

Seeing as this is line 184
		   term.setBackgroundColor(colors.orange)
Im guessing this program isn't the problem. Please post the program included in the error message.
My bad, i changed a few lines of code after posting the error line, updatedthe code in my post and as you can see the error is near a pullEvent function, wich makes more sense.
Here is the loop that has the error (its a simple mouse button):
while true do
			  event, button, xPos, yPos = os.pullEvent("mouse_click")
			  if xPos >= 15 and xPos <= 19 and yPos == 8 then
					 login()
			  elseif xPos >= 27 and xPos <= 35 and yPos == 8 then
					 register(false)
			  end
	   end


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 30 March 2014 - 08:58 AM

Let's assume either xPos or yPos is ending up as nil somehow. How about checking for that prior to your comparisons, and printing out what event/button/etc are set to?

if not (xPos and yPos) then
	print(event)
	print(button)
	print(xPos)
	print(yPos)
end


#5 RoD

  • Members
  • 313 posts

Posted 30 March 2014 - 09:41 AM

View PostBomb Bloke, on 30 March 2014 - 08:58 AM, said:

Let's assume either xPos or yPos is ending up as nil somehow. How about checking for that prior to your comparisons, and printing out what event/button/etc are set to?

if not (xPos and yPos) then
	print(event)
	print(button)
	print(xPos)
	print(yPos)
end
I implemented that code in my code.
I tried to only use that and ignore the button code and this is the result:
Spoiler

Then i tried to have all the code and add your code to mine:
Spoiler

EDIT: I realized that the terminate that was printing out was from the print(event), i ignored that line and added a term.setCursorPos(0,0) everytime ctrl+t is called. So, the program is now fixed. Thanks CometWolf and Bomb Bloke. Thread can be closed.

Edited by RoD, 30 March 2014 - 12:13 PM.


#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 30 March 2014 - 11:34 AM

Ok, so what that tells us is that in this instance, os.pullEvent("mouse_click") is able to return a "terminate" event. Unless I'm suffering a massive mental blank, that should not be happening.

For now, you can work around the issue (in that code block at least) with something like this:

while true do
	event, button, xPos, yPos = os.pullEvent("mouse_click")
	if event == "mouse_click" then
		if xPos >= 15 and xPos <= 19 and yPos == 8 then
			login()
		elseif xPos >= 27 and xPos <= 35 and yPos == 8 then
			register(false)
		end
	end
end

However, I'd be very interested to know what version of ComputerCraft you're running.

#7 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 30 March 2014 - 11:39 AM

This is because terminate event fires no matter what filter you give to os.pullEventRaw. To fix your issue just check if the fired event is mouse_click.

@Bomb Bloke: It has always worked like that (as far as I remember).

EDIT: Don't forget that he has set os.pullEvent to os.pullEventRaw at the start of his program.

Edited by MKlegoman357, 30 March 2014 - 11:46 AM.


#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 30 March 2014 - 11:53 AM

Ah - well I've learned something new. :)

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 30 March 2014 - 11:57 AM

View PostBomb Bloke, on 30 March 2014 - 11:34 AM, said:

Ok, so what that tells us is that in this instance, os.pullEvent("mouse_click") is able to return a "terminate" event. Unless I'm suffering a massive mental blank, that should not be happening.

View PostMKlegoman357, on 30 March 2014 - 11:39 AM, said:

@Bomb Bloke: It has always worked like that (as far as I remember).
Nope, some versions do allow termination when a filter is supplied, others do not allow it, although don't quote me on which versions are which :P

#10 RoD

  • Members
  • 313 posts

Posted 30 March 2014 - 12:11 PM

View PostBomb Bloke, on 30 March 2014 - 11:34 AM, said:

Ok, so what that tells us is that in this instance, os.pullEvent("mouse_click") is able to return a "terminate" event. Unless I'm suffering a massive mental blank, that should not be happening.

For now, you can work around the issue (in that code block at least) with something like this:

while true do
	event, button, xPos, yPos = os.pullEvent("mouse_click")
	if event == "mouse_click" then
		if xPos >= 15 and xPos <= 19 and yPos == 8 then
			login()
		elseif xPos >= 27 and xPos <= 35 and yPos == 8 then
			register(false)
		end
	end
end

However, I'd be very interested to know what version of ComputerCraft you're running.
Its fixed now, but the versions are:
  • Minecraft- 1.5.2
  • ComputerCraft- 1.53

Edited by RoD, 30 March 2014 - 12:11 PM.






3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users