Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Newbie learning event() call

Newbie learning event() call

Discuss PocketC for Palm OS (including Desktop Edition)

Postby wayne on Wed Dec 31, 2003 3:02 am

Hello,

I have been writing some simple code to learn how to use various calls. I have the latest versions of PocketC and PToolBox running on my T3 (w/ the update from Palm)

My understanding of the event call is that I can use it like a pause while waiting for an event. And it works like that in one program I have written, but in another, after the first use of the event call, it blows right through the event call (as in it doesn't wait 500 intervals (5 seconds))

where it works
//AAA
main(){
int f;
f=event(500);
puts('test 1-"+f+"\n");
f=event(500);
puts("test 2 -" + f+"\n");
f=event(500);
puts("test 3 -" + f+"\n");
}

I will note that when this runs the first two puts get printed right after one another when I type the screen. However the program waits for the third event.

However, in the following code, the last event is not waited on when I tap the screen w/ the stylus, even though I insert a sleep statement. But if I press a button then the last event gets waited on. And I understand why.

//CCC
library "PToolboxLib"
main(){
int first, x1,x2,x3,y1,y2,y3,m,e;
string names;
graph_on();
first=seconds();
e=event(100);
while(e==0){
m=seconds()-first;
puts (m+"\n");
setfgi(random(241));
x1=random(100);
x2=random(100);
x3=random(100);
y1=random(100);
y2=random(100);
y3=random(100);
tri(1,x1,y1,x2,y2,x3,y3);
e=event(100);
}
m=seconds()-first;
puts("last "+m+"\n");
sleep(10);
e=event(500);
m=seconds()-first;
puts("close "+e+" "+m+"\n");
}

So, with this code I can tell that if I don't press anything, I should get a gap of 5 seconds between printing the word 'last' and printing the word 'close'. However I don't. After I tap the screen once the prgram flies through and prints a value of three after the word 'close'

Will someone please explain what I'm not understanding about how this function works?:?:
wayne
 
Posts: 4
Joined: Fri Nov 14, 2003 1:10 pm

Postby Mikael on Wed Dec 31, 2003 7:39 pm

I am as stumped as you are, but with regard to the first piece of code you posted I did manage to make it work with the following:

//AAA

#define PAUSE 100
main(){

int e;

clear();

e=event(PAUSE);
e=event(PAUSE);
puts("test 1 -" + e+"\n");
e=event(PAUSE);
e=event(PAUSE);
puts("test 2 -" + e+"\n");
e=event(PAUSE);
e=event(PAUSE);
puts("test 3 -" + e+"\n");
wait();

}

which gives a pause of 2 seconds in between each execution and makes sure it doesn't shoot through to the end as before. This is probably a really clumsy way of doing it, but as I'm no great programmer, I won't knock it as long as it does the job. I've never tried more than 1 event in a row, so had no idea this type of problem existed. Hope this helps a little.

Mikael:)
Mikael
 
Posts: 156
Joined: Sun Apr 13, 2003 9:19 am
Location: Denmark

Postby Mikael on Wed Dec 31, 2003 7:57 pm

I've tried compiling the second app you posted but I'm having trouble with the 'setfgi(random(241));' function on line 12. It doesn't seem to part of PocketC and I can't find it in PToolbox; don't know if it's a typo. With regard to your app printing 3 after 'close' this is probably caused by a return of the last event type captured most likely a '3' or a 'pen up' event.

Just in case you don't know, the list runs as follows:

0 = Nothing
1 = Key entered
2 = Pen down
3 = Pen up
4 = Pen moved
5 = Page Up pressed
6 = Page Down pressed
7 = Calendar button pressed
8 = Address Book button pressed
9 = To Do button pressed
10 = Memo button pressed
11 = Menu button pressed

Mikael
Mikael
 
Posts: 156
Joined: Sun Apr 13, 2003 9:19 am
Location: Denmark

Postby jstadolnik on Wed Dec 31, 2003 8:06 pm

event(X) simply waits up to X ticks (1 tick=1/100 of a second) for an event to occur. It returns early if an event is detected. If a zero is returned, it means that the full time specified has expired without an event being detected.

Use sleep() call to wait for a specific period of time without testing for events.

setfgi() if on of PocketC's new built-in color functions.

Joe

The PToolboxLib guy.
http://www.geocities.com/retro_01775/PToolboxLib.htm
jstadolnik
 
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby Mikael on Thu Jan 01, 2004 12:28 pm

Hi,

I did manage to get you second app working with the following:

//CCC
library "PToolboxLib"
main(){

int first, x1,x2,x3,y1,y2,y3,m,e;
clear();

first=seconds();
m=seconds()-first;
puts("m= " + m+"\n");
e=event(100);

graph_on();
ClearBuf();

while(!e){
setfgi(random(241));
x1=random(100);
x2=random(100);
x3=random(100);
y1=random(100);
y2=random(100);
y3=random(100);
tri(1,x1,y1,x2,y2,x3,y3);
e=event(100);
}

graph_off();
clear();

m=seconds()-first;
puts("last "+m+"\n");
sleep(5000);
m=seconds()-first;
puts("close "+e+" "+m+"\n");
wait();
}

I think it does what you want i.e. prints a value, waits one second, draws some triangles, prints another value and then waits five seconds before printing the final value - also capturing any events in the meantime.

Mikael
Mikael
 
Posts: 156
Joined: Sun Apr 13, 2003 9:19 am
Location: Denmark

Postby wayne on Fri Jan 02, 2004 12:39 pm

First - thank you for all of the replies. I appreciate the help.

Yes, Mikael's code does a nice job of doing what the program is supposed to do, however my confusion with how the event call works started after the program was written on my palm. So my confusion is not as obvious as I would like.

However, after reading the comments and fiddling some more I have come to a conclusion!:D

Using the code below:

//EEE2
main(){
int k,f,m,first;
f=0;
clear();
first=seconds();
k=0;
m=seconds()-first;
puts("hello "+ m+" \n");
while(k < 6) {
k++;
f=event(300);
m=seconds()-first;
puts("test "+k+"a -"+ f + " - " +m+"\n");
f=event(300);
m=seconds()-first;
puts("test "+k+"b -"+ f + " - " +m+"\n");
f=event(300);
m=seconds()-first;
puts("test "+k+"c -"+ f + " - " +m+"\n");
sleep(1100);
puts("sleep over "+k+"\n");
}
}

My understanding of how the event() call works is that after a pen-down event, a pen-up event is created (pardon me for not knowing the correct technical term to use) and held for the next event call to off the stack (if nothing else is happening event wise??? I have not tested multiple events to see if they 'stack up') After that second event is used, the event() call goes back to a 'waiting' state of value zero.

However - (and this is interesting) If you press a key during an event, a second value is placed on the event() stack - a key-up value, similar to a pen-up value. What is weird is that this key-up event is zero also, but it doesn't act like the value zero. When I run my odd little code above, if I press a key during the "a" cycle, then the "b" test instantly gets a zero value printed (please see output below) Test "a" is a screen tap and test "b" is a quick key press.

hello 0
test 1a -2 - 1
test 1b -3 - 1
test 1c -0 - 4
sleep over 1
test 2a -5 - 6
test 2b -0 - 6
test 2c -0 - 9
sleep over 2
. . . . .

My understanding of programming languages is limited, however it seems odd that the key-up event is recognized but there is no code assigned to it. As a secondary issue, it seems that the voice memo and the center button the D-pad do not have codes assigned to them.

Again, thank you to everyone who did reply and anyone else who read my meandering code snippets.

wwc
wayne
 
Posts: 4
Joined: Fri Nov 14, 2003 1:10 pm


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 1 guest

cron