HP Forums
[HP-Prime] Picking elements from a List in a program - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: [HP-Prime] Picking elements from a List in a program (/thread-255785.html)



[HP-Prime] Picking elements from a List in a program - Jean-Michel - 11-14-2013

Hello



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:

{{x,y,...}{}}

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

{{x,y,...}}

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

I was thinking that

SUB(SUB(MOUSE(),1,1),1,1)

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.



Re: [HP-Prime] Picking elements from a List in a program - Tim Wessman - 11-14-2013

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.

TW


Re: [HP-Prime] Picking elements from a List in a program - Jean-Michel - 11-14-2013

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?

[edit:]

case 1:

myvar:={1,2,3,4}

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.


Re: [HP-Prime] Picking elements from a List in a program - dg1969 - 11-15-2013

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

friendly :o)