android
  #1  
Old 05-17-2010, 01:08 PM
Donone Donone is offline
Junior Member
 
Join Date: May 2010
Posts: 59
Default Can the event buffer/stack be cleared?

When clicking the screen to select the application from the menu, that click seems to be carried through and counts as a click inside the now running application. That causes a button to be pressed that was unintentional.

I need to clear any outstanding clicks (or other events) once the application has started.

Any thoughts please?
Reply With Quote

Advertisement [Remove Advertisement]

  #2  
Old 05-17-2010, 01:20 PM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Hm, I don't have this trouble. How do your main loop read for the click?

One way to "hard" clear it is by simply adding this function:
Code:
--Clear event que function
function clearQue()
	os.wait(50)
	while (control.read()==1) do 
		control.isTouch()
	end
end
And just call that whenever you want to clear it. Brett_val tipped me about this ^^
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

  #3  
Old 05-17-2010, 01:35 PM
Donone Donone is offline
Junior Member
 
Join Date: May 2010
Posts: 59
Default

Thanks for responding Habhome. I have been using the Apeopex routines. I can only assume that maybe I keep the mouse/finger on the screen too long. It is a definite problem because I can avoid it by clicking in the menu in a position where my Start button will not appear.

I will certainly give your routine a try, many thanks.
Reply With Quote

  #4  
Old 05-17-2010, 01:47 PM
Brett_val's Avatar
Brett_val Brett_val is offline
Senior Member
 
Join Date: Jan 2010
Location: The Netherlands
Posts: 636
Default

Wow, I've seen some troubles with the event queue, but none involving clicks before the app even started..

Could you post the code that causes this, or even better, the whole app?



ps. Great idea putting it into a function Habhome

EDIT
Quote:
Originally Posted by Donone View Post
I can avoid it by clicking in the menu in a position where my Start button will not appear.
That's certainly an indication that a touch event is still in the queue, I'm really hoping that your app's code will provide some more insight on this..
Reply With Quote

  #5  
Old 05-18-2010, 02:04 AM
Donone Donone is offline
Junior Member
 
Join Date: May 2010
Posts: 59
Default

The following code extract is where the problem occurs. It is NOT consistent, but if the menu entry for this program is clicked and the click is over where the Start Button will appear, gStart [sometimes] becomes true and passes the test in the repeat loop. Perhaps it is to do with the length of click or a movement once clicked. I can see nothing wrong with the code, it works otherwise. The provided function to cure does seem to work.
Over to you... Any other comments always welcome.

Code:
gStart=false
OnTouchClick = nil

function TouchEvent(x,y)
local Changed, Col, Row = false, gCurOldC, gCurOldR
--Check Start button
	if (x>4) and (x<47) and (y>210) and (y<244) then
	print("Start pressed")
		gStart = not gStart
		ReverseButton()
                Box[x]  =  Box[x] +-1
	end
... more testing code is here
end

IN HERE A CUTDOWN VERSION OF Apeopex (without user buttons)
function GetEvent()
  if (control.read(1) == 1) then
    if (control.isTouch() == 1) then
      local x, y = touch.pos();
		if (touch.down() == 1) then
			if (OnTouchDown ~= nil) then
				OnTouchDown(x,y);
			end;
		elseif (touch.up() == 1) then
			if (OnTouchUp ~= nil) then
				OnTouchUp(x,y);
			end;
		elseif (touch.click() == 1) then
			if (OnTouchClick ~= nil) then
				OnTouchClick(x,y);
			end;
		elseif (touch.move() == 1) then
			if (OnTouchMove ~= nil) then
				OnTouchMove(x,y);
			end;
		end;
...
...
end

OnHomeClick = ExitApp
OnTouchClick = TouchEvent
--*****************************
repeat
    GetEvent()
	if gStart then
		Update()
	end
until (gExit == true)
Reply With Quote

  #6  
Old 05-18-2010, 03:28 AM
Habhome's Avatar
Habhome Habhome is offline
Moderator
 
Join Date: Jan 2010
Location: Sweden
Posts: 1,079
Default

Do you declare the x and y variables in the start of your code? And if you don't try to do that by setting them to a value where a click wouldn't do anything, -1 perhaps.
Code:
x = -1
y = -1
I always do that in my code, usually = 0 though it doesn't matter really.
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine
Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it!
Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it.
Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^
Reply With Quote

  #7  
Old 05-18-2010, 04:56 AM
Donone Donone is offline
Junior Member
 
Join Date: May 2010
Posts: 59
Default

The only 'declaration' is in the GetEvent (Apeopex)...
Code:
local x, y = touch.pos();
in that they are local but have no value until set by the event.
I think you are suggesting that maybe they have a random value at that point.
Thank you for making the point.
I will certainly try that, especially as I have been too loose with such matters due to eagerness. Normally I declare everything, but Lua seems very forgiving, nay, too forgiving.
Reply With Quote

  #8  
Old 05-18-2010, 05:35 AM
Brett_val's Avatar
Brett_val Brett_val is offline
Senior Member
 
Join Date: Jan 2010
Location: The Netherlands
Posts: 636
Default

The program doesn't start before you lifted your finger from the screen, so it can't be a hold or a move from selecting the program from the menu.

I'm thinking there are some events left in the queue from the last time this program ran.
Does the exit button happen to be at the same place as the Start button?

For example when a touch.down exits the app, a touch.click at that same place is still in the queue.

Last edited by Brett_val; 05-18-2010 at 07:25 AM.
Reply With Quote

  #9  
Old 05-18-2010, 12:56 PM
Donone Donone is offline
Junior Member
 
Join Date: May 2010
Posts: 59
Default

Thanks Brett_val. Unfortunately no, the exit is done by HomeClick as suggested by Habhome, so it is not a screen position.
Today I removed the routine suggested by Habhome and it still has not gone wrong, embarrassingly.
You may have a clue with your suggestion because I do tend to do small code changes and then re-run, so I run very often. Perhaps something did get left, I hasten to add, if I did not say so, that this is on the simulator, I have not tried that problem live because it was intermittent.

I hope this was not a red herring or fluke.
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 11:42 PM.