Jump to content




Mouse Help


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

#1 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 12 October 2012 - 07:31 AM

I am trying to make a program to constantly wait for mouse input then compare it to the table.
However it will not work.
Please ignore the "she" function I was going to parallel with shell after it worked but It wouldn't work.
Remember most the code was me trying to debug it.
I would really love if you guys could explain the best way to do it.
local mouse = {
  [1] = {buttonX = 1, buttonY = 2, command = "print('Hi')"}
}
local function she()
  shell.run("shell")
end
local function getMouse()
  while true do
    event, p1, p2, p3 = os.pullEvent()
    if event == "click" then
	  for k, v in ipairs(mouse) do
	    if mouse[k].buttonX == p1 and mouse[k].buttonY == p2 then
		  print("hi")
	    end
	  end
    end
  end
end
getMouse()


#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 12 October 2012 - 07:34 AM

What version on you running this on? The mouse clicks only work in the current beta of 1.45 pr1. If you're using that and having issues you should post that in the beta section of the forums and not here.

#3 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 12 October 2012 - 07:37 AM

View Postluanub, on 12 October 2012 - 07:34 AM, said:

What version on you running this on? The mouse clicks only work in the current beta of 1.45 pr1. If you're using that and having issues you should post that in the beta section of the forums and not here.
I am using the beta however this is a VERY general question. I am asking how to compare a var to a var in a table.

#4 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 12 October 2012 - 07:49 AM

It depends on how the table is formated. I think you're table is formatted wrong. But not sure I will have to play with it some. For a standard table that has it values assigned like tTable[1], and not tTable[putWhatYouWantHere] then you can simply do:
tTable = {1,2}

event, p1, p2, p3 = os.pullEvent()
  if p2 == tTable[1] and p3 == tTable[2] then
	 --it matches
  else
	--it does not match
  end
end

I think your using a custom setup like tTable[whatYouWantHere], which using ipairs in the for loop should be correct. I will play with it more and see if I cant find your problem


EDIT: Part of the problem I noticed is that your checking p1 which is the event type so for a mouse click p1 will == "click"

Edited by luanub, 12 October 2012 - 07:51 AM.


#5 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 12 October 2012 - 08:02 AM

View Postluanub, on 12 October 2012 - 07:49 AM, said:

It depends on how the table is formated. I think you're table is formatted wrong. But not sure I will have to play with it some. For a standard table that has it values assigned like tTable[1], and not tTable[putWhatYouWantHere] then you can simply do:
tTable = {1,2}

event, p1, p2, p3 = os.pullEvent()
  if p2 == tTable[1] and p3 == tTable[2] then
	 --it matches
  else
	--it does not match
  end
end

I think your using a custom setup like tTable[whatYouWantHere], which using ipairs in the for loop should be correct. I will play with it more and see if I cant find your problem


EDIT: Part of the problem I noticed is that your checking p1 which is the event type so for a mouse click p1 will == "click"
Thanks for the help!
But correction! The "click" event returns p1 as x, p2 as y and p3 as the mouse button such as 1,2,3,4,5.

#6 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 12 October 2012 - 08:33 AM

lol ya I realized that on my way home from work. My brain is fried after a long boring night at work with nothing to do...

#7 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 12 October 2012 - 10:23 AM

So its weird. The first time I ran it I got a weird error about a number with a ?. Then I commented out some stuff, did a whole bunch of debugging that told me that it should work as is... Removed the debug and comments and it works...

Try it again..?? It seems to work fine for me.

#8 PonyKuu

  • Members
  • 215 posts

Posted 12 October 2012 - 12:14 PM

Doesn't os.pullEvent() return an event type as the first value? If you make something like this:

local event, sender, message = os.pullEvent ("rednet_message")

event always will be equal to the string "rednet_message"...

#9 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 12 October 2012 - 02:32 PM

View PostPonyKuu, on 12 October 2012 - 12:14 PM, said:

Doesn't os.pullEvent() return an event type as the first value? If you make something like this:

local event, sender, message = os.pullEvent ("rednet_message")

event always will be equal to the string "rednet_message"...
The point of this is to run in the background so you can have multiple buttons but also do other stuff.

#10 PonyKuu

  • Members
  • 215 posts

Posted 12 October 2012 - 02:54 PM

Oh, I'm sorry, I have misread the code...

#11 GopherAtl

  • Members
  • 888 posts

Posted 12 October 2012 - 03:13 PM

View Postluanub, on 12 October 2012 - 07:34 AM, said:

What version on you running this on? The mouse clicks only work in the current beta of 1.45 pr1. If you're using that and having issues you should post that in the beta section of the forums and not here.

I'm not an authority of any sort but I'm pretty sure the beta forum is for formal bug reports ONLY, not for support on how to use the new features.

I'd guess help q's like this belong in this subforum, but they should have titles starting with [1.45pr1], or whatever version they apply to.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users