Post Reply 
MOUSE returns Invalid Input
12-14-2013, 07:30 PM
Post: #1
MOUSE returns Invalid Input
My goal with the program is to eventually have the user touch one of the "four corners", which each touch turning the a certain color on (from upper left hand: red, green, blue, yellow). I am not all the way there yet. I am having trouble getting input with the MOUSE command - keep getting "Invalid Input" error. And I am stuck to finding where my error is.

Program I have so far:

EXPORT FOURSQUARE()
BEGIN
LOCAL mx, my, L0;
mx=-1; my:=-1;

REPEAT
RECT();
RECT_P(0,0,318,200);
RECT_P(0,201,318,218,0);
TEXTOUT_P("EXIT",130,218,3,
RGB(255,255,255));
WAIT(-1);
L0:=MOUSE();
mx:=B→R(L0(1,1));
my:=B→R(L0(1,2));

// draw boxes here

UNTIL my≥201;
RETURN "DONE";
END;

Map:
(0,0) to (158, 100): red box that lights up with a touch
(159, 0) to (318,100): blue box that lights up with a touch
(0, 101) to (158, 200): yellow box that lights up with a touch
(159, 101) to (318, 200): green box that lights up with a touch
(0, 200) to (218, 318): black exit box. Touch this region to terminate program.

Any help is appreciated.
Visit this user's website Find all posts by this user
Quote this message in a reply
12-14-2013, 08:12 PM
Post: #2
RE: MOUSE returns Invalid Input
Hi, I have just started playing with PPL myself and very much still learning the basics, however I think the alternative below should work for you?

EXPORT FOURSQUARE()
BEGIN
LOCAL mx, my, L0;
mx=-1; my:=-1;

REPEAT
RECT();
RECT_P(0,0,318,200);
RECT_P(0,201,318,218,0);
TEXTOUT_P("EXIT",130,218,3,RGB(255,255,255));
L0:=WAIT(-1);

IF SIZE(L0)>1 THEN
mx:=L0(2);
my:=L0(3);

// draw boxes here

END;

UNTIL my≥201;
RETURN "DONE";
END;

Jacob
Visit this user's website Find all posts by this user
Quote this message in a reply
12-14-2013, 08:51 PM
Post: #3
RE: MOUSE returns Invalid Input
No such luck.
Visit this user's website Find all posts by this user
Quote this message in a reply
12-14-2013, 09:16 PM (This post was last modified: 12-14-2013 11:41 PM by Han.)
Post: #4
RE: MOUSE returns Invalid Input
Did you check to see if MOUSE() returned an empty list? The very first instance of MOUSE() may very well return an empty list, in which case L0(1,1) and L0(1,2) would cause errors.

Code:

L0:=MOUSE();

// check if we have valid mouse input
IF (SIZE(L0(1)) OR SIZE(L0(2))) THEN

  // handles first mouse
  IF SIZE(L0(1)) THEN
    // code here for mouse 1
  END;

  // handles second mouse
  IF SIZE(L0(2)) THEN
    // code here for mouse 2
  END;

END;

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
12-14-2013, 10:29 PM
Post: #5
RE: MOUSE returns Invalid Input
(12-14-2013 08:51 PM)Eddie W. Shore Wrote:  No such luck.

Maybe I'm misunderstanding what you're trying to do, I thought your goal was to do something similar to what the code below does:

Code:
EXPORT FOURSQUARE()
BEGIN
LOCAL mx, my, L0;
mx=-1; my:=-1;

RECT();
RECT_P(0,0,320,200);
RECT_P(0,201,320,240,0);
TEXTOUT_P("EXIT",147,214,3,RGB(255,255,255));

REPEAT

L0:=WAIT(-1);

IF SIZE(L0)>1 THEN
mx:=L0(2);
my:=L0(3);

CASE
 IF mx<160 THEN
  CASE
   IF my<100 THEN RECT_P(0,0,320,200,RGB(255,0,0)); END;
   IF my<201 THEN RECT_P(0,0,320,200,RGB(255,255,0)); END;
  END;
 END;
 IF mx>159 THEN
  CASE
   IF my<100 THEN RECT_P(0,0,320,200,RGB(0,0,255)); END;
   IF my<201 THEN RECT_P(0,0,320,200,RGB(0,255,0)); END;
  END;
 END;
END;

END;

UNTIL my>200; 
RETURN "DONE";
END;

Jacob
Visit this user's website Find all posts by this user
Quote this message in a reply
12-14-2013, 10:53 PM (This post was last modified: 12-16-2013 06:44 PM by Damien.)
Post: #6
RE: MOUSE returns Invalid Input
Hi, everyone,

maybe something like that should work...


Code:

//-------------------------------------------
// MOUSE() ... 
//  
EXPORT MOUZ()
BEGIN
 LOCAL grey=#707070h;
 LOCAL s,DEP=0; 
 LOCAL x1,y1,xo1,yo1; 
 RECT_P(G0,0,0,319,219,grey);
 DRAWMENU("","","","","","QUIT");
 WHILE GETKEY() ≠ 4 DO // Esc to QUIT
  CASE
// :::::::::1 FINGER ::::::::::
   IF (MOUSE(0)≠−1 AND MOUSE(1)≠−1) AND
      (MOUSE(5)==−1 AND MOUSE(6)==−1)
   THEN 
     xo1:=B→R(MOUSE(2));
     yo1:=B→R(MOUSE(3));
     y1:=B→R(MOUSE(1));
     x1:=B→R(MOUSE(0));
    CASE
     IF 0<xo1<158 AND 0<yo1<100 THEN RECT_P(0,0,158,100,#FF0000h); END;
     IF 159<xo1<318 AND 0<yo1<100 THEN RECT_P(159,0,318,100,#FFh); END;
     IF 0<xo1<158 AND 101<yo1<200 THEN RECT_P(0,101,158,200,#FFFF00h); END;
     IF 159<xo1<318 AND 101<yo1<200 THEN RECT_P(159,101,318,200,#00FF00h); END;
    DEFAULT
    END;
// :::::::: MENU ::::::::: 
    IF y1>219 THEN 
     CASE
      IF   0<x1< 52 THEN END;
      IF  52<x1<105 THEN END;
      IF 105<x1<158 THEN END;
      IF 158<x1<211 THEN END;
      IF 211<x1<264 THEN END;
      IF 264<x1<319 AND DEP≠ 0 THEN BREAK; END;
     DEFAULT
     END; 
    END;
   END;
// :::::::: 0 FINGER :::::::::
   IF (MOUSE(0)==−1 AND MOUSE(1)==−1) AND
      (MOUSE(5)==−1 AND MOUSE(6)==−1) 
   THEN
    RECT_P(G0,0,0,319,210,grey);
    DEP:=1;  
   END; 
  END; 
 END; //While
END;


Regards,


Damien.
Find all posts by this user
Quote this message in a reply
12-16-2013, 08:38 AM
Post: #7
RE: MOUSE returns Invalid Input
hello

have a look at this code

Code:

Colors= { #FF0000h, #FF00h, #FFh, #FF00FFh }; // pre defined color list
EXPORT FOURSQUARE()
BEGIN
 while 1 do
  RECT();
  RECT_P(0,0,318,200);
  RECT_P(0,201,318,218,0);
  TEXTOUT_P("EXIT",130,218,3,RGB(255,255,255));
  local l:=WAIT(-1); // wait for a user input
  IF TYPE(l)=6 and l(1)=#0 THEN // verify that we have a list corresponding to a mouse down...
   local mx:=l(2)/#160d, my:=l(3)/#100d; // x and y for the rectangle (0 or 1 in each case!)
   if my>=2 then return "DONE"; end; // well, or maybe 2!!!!
   rect_p(mx*#160d, my*#100d, mx*#160d+#160d, my*#100d+#100d, Colors(mx*2+my+1)); // draw the rectangle
   wait(0.2); // wait so we see it!
  END;
 end; 
END;

cyrille
Find all posts by this user
Quote this message in a reply
12-17-2013, 03:58 AM
Post: #8
RE: MOUSE returns Invalid Input
Quote:have a look at this code

Some interesting techniques in that code, thanks for sharing!

Jacob
Visit this user's website Find all posts by this user
Quote this message in a reply
12-17-2013, 01:49 PM
Post: #9
RE: MOUSE returns Invalid Input
I echo Jacob's comment. Thank you for sharing.
Visit this user's website Find all posts by this user
Quote this message in a reply
12-20-2013, 04:34 PM
Post: #10
RE: MOUSE returns Invalid Input
There's an example for using MOUSE in a German Wiki:
http://wiki.hp-prime.de/index.php?title=...nsprogramm
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)