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



#2

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.


#3

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


#4

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.


#5

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

friendly :o)


Possibly Related Threads...
Thread Author Replies Views Last Post
  Sending little images to the Prime (...and Program name bug?) Erwin Ried 19 782 12-10-2013, 05:35 PM
Last Post: Erwin Ried
  Problem with debug HP prime program, somebody help me? Carlos CM (Mexico) 6 453 12-05-2013, 03:07 PM
Last Post: Carlos CM (Mexico)
  Milestones:List of IEEE Milestones -> HP-35 AlbertTocarLoseggs 4 294 11-27-2013, 08:52 AM
Last Post: Massimo Gnerucci (Italy)
  HP PRIME: APP program code DISAPPEARS !! Joseph Ec 0 151 11-25-2013, 11:35 AM
Last Post: Joseph Ec
  Prime: Placing more than 1 item on the RPN stack in a single program? John Colvin 4 318 11-19-2013, 08:59 AM
Last Post: Miguel Toro
  Prime: Program size limited to 64K? Erwin Ried 4 290 11-17-2013, 11:42 PM
Last Post: Joseph Ec
  HP-Prime : Extracting elements from a list in RPN Miguel Toro 0 221 11-15-2013, 06:44 PM
Last Post: Miguel Toro
  HP Prime: Recommendation for future RPN Program Mode BruceTTT 3 258 11-13-2013, 10:03 PM
Last Post: BruceTTT
  HP Prime: run a program in another program Davi Ribeiro de Oliveira 6 358 11-11-2013, 08:28 PM
Last Post: Davi Ribeiro de Oliveira
  Hp PRIME - how to send a list to the connectivity Kit giancarlo 1 212 11-10-2013, 11:50 AM
Last Post: Tim Wessman

Forum Jump: