HP Forums

Full Version: [HP-Prime] Picking elements from a List in a program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


I'm currently learning about the MOUSE() command used to detect where a finger is touching the screen.

It returns a list of lists with following structure:


where x and y are the coordinates of the points where the touchscreen is hit. At least this is what I understood...

I tried to use the SUB() command to extract x and y (separately or as a list {x,y}), but did not get better result than


i.e. a list of list of the first term of the list returned by MOUSE().

I was thinking that


would return x coordinate of the touch point, but it does not.

I did not find any other command dealing with lists that could do the job.

Did I miss something, am I doing something wrong (probably !)

Help much appreciated.

Kind regards.

I'd recommend storing the return from mouse into a local variable. The reason why is that it is an EXACT snapshot of the instant that command is evaluated. Thus you have the potential to check the state, then in the few ms between when you check it and begin to try and evaluate the state may have changed.

Then you can use direct indexing myvar(1,1) and so on to access the specific pieces directly.

Note you can also do MOUSE(1) or MOUSE(2) which returns -1 if nothing is there, or else the list.


Thanks Tim for your advice.

In fact, even if I did not mention it in my post, I already tried this solution (storing the value in a variable. Even tested local or exported variable).

What do you mean, please, by "direct addressing"? Which instruction does this?


case 1:


SUB(myvar,1,2) --> {1,2} as expected

case 2:

myvar:={{1,2,3,4},{5,6,7,8}} --> list of lists, as MOUSE() returns

SUB(myvar,1,1) --> {1,2,3,4} as expected

SUB(SUB(myvar,1,1)),1,1) --> {{1,2,3,4}} (not the the double brackets) where {1} would be expected

[edit 2:]

Got it!

(direct addressing)

Edited: 14 Nov 2013, 5:54 p.m.

I mean you can try myvar(2,3) => 7 with myvar:={{1,2,3,4},{5,6,7,8}}

friendly :o)