Doubt using gui.event

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Doubt using gui.event

apeine
Hello fellow Plua programmers,

I created two programs, as below:

-- teste.lua
screen.clear(0)
for y=1, 160, 1 do
screen.box(0,y,160,2,screen.rgb(0,255,0))
act=gui.event(50)
screen.box(0,y,160,2,0)
if act==penDown then
    break
end
end
for x=1, 160, 1 do
screen.box(x,0,2,160,screen.rgb(0,255,0))
act=gui.event(50)
screen.box(x,0,2,160,0)
if act==penDown then
    break
end
end
repeat
act=gui.event()
until act~=nilEvent

and:

-- wait.lua
screen.clear(0)
repeat
act=gui.event()
until act~=nilEvent

The first one draws a horizontal line moving top to bottom, then a
vertical line moving left to right. If I touch the screen (using
gui.event penDown) on the first part (top-bottom), it stops and goes
to left-right. If I touch the screen again, it should go to a blank
(black) screen and wait for another screenpress. Which does not occur.
The programs quits right after the second screenpress. If I don't
touch the screen, breaking the second movement (left-right), the blank
screen shows and wait for screenpress, as expected.
Then the second program does what the last part of the first program
should do. A blank (black) screen waiting for a screenpress.
What am I doing wrong? I tried to clear the variable, but it didn't work.

Reply | Threaded
Open this post in threaded view
|

Re: Doubt using gui.event

migueletto-2
Hi,

> repeat
> act=gui.event()
> until act~=nilEvent

> If I touch the screen again, it should go to a blank
> (black) screen and wait for another screenpress. Which does not occur.
> The programs quits right after the second screenpress.

When you tap the screen you generate two events: penDown and penUp.
The repeat loop above exits when it receives something different from
nilEvent, which is the case of penUp.

By the way, checking for nilEvent after calling gui.event() without
parameters is not going to work, since no nilEvent will be raised.

Regards,
Marcio.


Reply | Threaded
Open this post in threaded view
|

Re: Doubt using gui.event

apeine
Well Marcio,

the program does wait for a screenpress or whatever to happen.
Guess I'll change for

until act==penDown

Thanks for your help. Regards,

Alfredo

--- In [hidden email], "migueletto" <migueletto@...> wrote:

>
> Hi,
>
> > repeat
> > act=gui.event()
> > until act~=nilEvent
>
> > If I touch the screen again, it should go to a blank
> > (black) screen and wait for another screenpress. Which does not occur.
> > The programs quits right after the second screenpress.
>
> When you tap the screen you generate two events: penDown and penUp.
> The repeat loop above exits when it receives something different from
> nilEvent, which is the case of penUp.
>
> By the way, checking for nilEvent after calling gui.event() without
> parameters is not going to work, since no nilEvent will be raised.
>
> Regards,
> Marcio.
>