UserInput Mouseup and Doublemouseup

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

JamesWebster
Posts: 25
Joined: Sun Aug 07, 2011 11:36 am

UserInput Mouseup and Doublemouseup

Post by JamesWebster » Sat Sep 10, 2011 8:25 am

Hello,

I've been working on the project, I've already posted once. The first part is now fully functional. What I'm worrying about is the User input part. It doesn't work it's supposed to. If you doubleclick it's supposed to say mismatch as the answer. If you click it's supposed to say match as the answer. Comparing the answer with the truth the error counting is supposed to work. But it doesn't. Furthermore if the user doesn't do anything before the next letter is shown it's supposed to count this as a mistake.
I don't know how to get the user input working with repetitious doubleclick and click events, can anyone help me out?

best regards
James
Attachments
Tipp_userinput.livecode.zip
(3.9 KiB) Downloaded 108 times
Last edited by JamesWebster on Sat Sep 10, 2011 6:56 pm, edited 1 time in total.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: UserInput Mouseup and Doublemouseup

Post by Dixie » Sat Sep 10, 2011 10:23 am

Hi...

You haven't put any scripts in place that use 'mouseUp' or 'mouseDoubleUp'... so, I don't think anyone can help until you do.

Dixie

Klaus
Posts: 11057
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by Klaus » Sat Sep 10, 2011 11:38 am

Hi James,

a general hint:
"mousedoubleup" will also and always trigger a "mouseup" unless you add
some very smart scripting to the "mouseup" and "mousedoubleup" handler!

And no, your example stack does not show your problems in any way 8)


Best

Klaus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2350
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by jmburnod » Sat Sep 10, 2011 1:36 pm

Hi Dixie,

Yes there is one script with mousedoubleup in the script of cd "nbback"
but it is difficult to understand the problem

Code: Select all

local tOutput
global tOutputArray
global xback
global matches
global totallaenge
global Editmodus

local aktuell
global Fehleranzahl
global WarteCon
global Antwort
global Wahrheit
global durchgang
On Preopencard
      local abc
   local tAChar
   local tCollect
   local numbers
   local temp
   local positionofmatches
    put "" into tOutput
   put "BCDFGHJKMNPQRSTVXZ" into abc #start Values
   repeat with x=1 to totallaenge # create nomatch-Kette
               put char random(18) of abc after tCollect
     if (char (length (tCollect)- xback) of tCollect = (last char of tCollect))  then
      repeat #create mismatch
                              put char random(18) of abc into tAChar
                              if tAChar <> last char of tCollect then
                                    put tAChar into last char of tCollect
                                    -- we found a new random letter, get out of repeat loop
                                    exit repeat
         end if
      end repeat
   end if
end repeat

      -- creating the array
      repeat for each char aChar in tCollect
         put aChar & space after tOutPut
      end repeat
      delete last char of tOutPut -- a space
   split tOutput by space
   #bis jetzt haben wir eine Buchstabenkette, in der es keinen match nach dem Kriterium xback gibt!
   
   put "" into tCollect #Überflüssig
   # Create Random numbers, which indicate matches
repeat with x=1 to totallaenge-xback #Create an array with every number
   put x+xback into numbers[x] # +xback -> Andernfalls kommen matches auch am Anfang vor
end repeat
repeat with x=1 to totallaenge-xback #shuffle array with every number
   put Random(totallaenge-xback) into tAChar
   put numbers[tAChar] into temp
   put numbers[x] into numbers[tAChar]
   put temp into numbers[x]
end repeat
   repeat with x=1 to matches #Punkte in der Kette festlegen für matches, es kann keine doppelten geben :)
   put numbers[x] into positionofmatches[x]
   put positionofmatches[x] && tCollect into tCollect
end repeat
# Ziel: das erzeugen der Matches, jetzt müssen die Positionen innerhalb neu besetzt werden
repeat with x=1 to matches
   If EditModus is "false" then
   put tOutput[positionofmatches[x]-xback] into tOutput[positionofmatches[x]]
Else
   #put "*" into tOutput[positionofmatches[x]] # Zählbarkeit der Matches zum Ausprobieren erleichtert
   put tOutput[positionofmatches[x]-xback] into tOutput[positionofmatches[x]] #Ausprobieren der Usereingabe
      End if
end repeat
   put "" into tCollect #Überflüssig
repeat with x=1 to totallaenge
   put tOutput[x] into tOutputArray[x]
    put tCollect && tOutputArray[x] into tCollect
end repeat
disable fld "letters"
      put tCollect into field "letters" #Bis hierher einwandfrei!
   put 0 into aktuell
   put 0 into Fehleranzahl[durchgang]
   split tOutput with space
      send "nbacktiming" to me in 10 milliseconds
end Preopencard

# Usereingabe
On MouseUp
   put "match" into Antwort
   If (tOutputArray[aktuell] is tOutputArray[aktuell-xback]) then
      put "match" into Wahrheit
   Else
      put "mismatch" into Wahrheit
   End if
             disable fld "Antwort"
             put Antwort into fld "Antwort"
             put Wahrheit into fld "Wahrheit"
end MouseUp
On MouseDoubleUp
   #put "mismatch" into Antwort
         If (tOutputArray[aktuell] is tOutputArray[aktuell-xback]) then
      put "match" into Wahrheit
   Else
      put "mismatch" into Wahrheit
   End if
                disable fld "Antwort"
             put Antwort into fld "Antwort"
             put Wahrheit into fld "Wahrheit"
end MouseDoubleUp

On nbacktiming
   put (aktuell & "- Fehlerzahl: " & Fehleranzahl[durchgang]) into field "numbers"
   add 1 to aktuell
   If aktuell <= totallaenge then
      If Random(4) is 1 then # zufällige Auswahl ob groß oder kleinbuchstabe
         put ToLower(tOutputArray[aktuell]) into field "letter"
      Else
         put tOutputArray[aktuell] into field "letter"
      end if
      #Usereingabe bzw. keine Usereingabe und Fehlerzählen
      If aktuell > xback then
         Mouseup
         MouseDoubleup
         If fld "Antwort" = fld "Wahrheit" then
            Else
               add 1 to Fehleranzahl[durchgang]
         End if
      End if
      #Wait for 500 millisec with messages
      send "clearField" to me in 500 milliseconds
      send "nbacktiming" to me in 3000 millisec
   Else
      delete local aktuell
      put "" into field "letter"
      put 1 into WarteCon
      If durchgang is 1 then
         go to card "Cons_E1"
      End if
      If durchgang is 2 then
         go to card "Cons_E2"
      End if
      If durchgang is 3 then
         go to card "Cons_E3"
      End if
   End if
end nbacktiming
on clearField
   put "" into field "letter"
end clearField
on closeCard # so nbacktiming doesn't go on forever
   repeat for each line aLine in the pendingMessages
      if aLine contains "nbacktiming" then cancel item 1 of aLine
   end repeat
end closeCard
Best regards
Jean-Marc

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: UserInput Mouseup and Doublemouseup

Post by Dixie » Sat Sep 10, 2011 3:50 pm

Jean-Marc,

You quite right, I only opened the stack at the first card and did not look in the application browser until I read your post... but I think that I will have to leave this one to someone like Klaus as my German is restricted to 'Boris Becker', 'Audi' and 'Mercedes-Benz'... :-)

be well

Dixie

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2350
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by jmburnod » Sat Sep 10, 2011 4:23 pm

Dixie,
my German is restricted to 'Boris Becker', 'Audi' and 'Mercedes-Benz'
It is true also for my german and my english too there are terrible, but it seem i progress in english :D
In fact i lost my german when i tried learn english

All the best

Jean-Marc

Klaus
Posts: 11057
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by Klaus » Sat Sep 10, 2011 4:46 pm

Hi James,

Ok, I took a look but have no idea what should happen here but doesn't 8)

But I can give you some important hints:
Use parentheses when using EXPRESSIONS (a - b) in the keys of an ARRAY -> put Z into tArray[(a - b)]
Otherwise you might get unexspected results!

Code: Select all

...
# Ziel: das erzeugen der Matches, jetzt müssen die Positionen innerhalb neu besetzt werden
repeat with x=1 to matches
  If EditModus is "false" then

     ## Like here:
     put tOutput[(positionofmatches[x]-xback)] into tOutput[positionofmatches[x]]
  Else
     ## ... and here:
    put tOutput[(positionofmatches[x]-xback)] into tOutput[positionofmatches[x]] #Ausprobieren der Usereingabe
  End if
...
Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6069
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: UserInput Mouseup and Doublemouseup

Post by dunbarx » Sat Sep 10, 2011 6:23 pm

I have alsways used the old HC method:

on mouseup
wait 20
if the mouseClick then
beep 2
--doDoubleStuff
else
beep 1
--doSingleStuff
end if
end mouseUp

This old fashioned method bypasses the issues that putting a mouseUp and a mouseDoubleUp handler in the same script.

I have even extended this to allow triple clicks (and beyond).

Craig Newman

Klaus
Posts: 11057
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by Klaus » Sat Sep 10, 2011 6:31 pm

Hi Craig,

way cool, thanks :)

New trick for an old pony 8)


Best

Klaus

JamesWebster
Posts: 25
Joined: Sun Aug 07, 2011 11:36 am

Re: UserInput Mouseup and Doublemouseup

Post by JamesWebster » Sat Sep 10, 2011 7:04 pm

Hi everyone,
Sorry about the file! - Actually I've created an english commented version with just the necessary card. I've corrected the upload! If you open the card, you can see that letters are shown. While showing a letter until the next is shown the userinput is supposed to take place. If you click it's supposed to put "match" into "Antwort". If you doubleclick it's supposed to put "mismatch" into "Antwort". Then you compare it with a the truth "Wahrheit", which is either "match" or "mismatch" to see if the user is correct.
I hope it's a bit easier to get the idea with an english commented script and another try to explain what I want to do.
Hey Klaus, the array I'm using is containing numbers, which are (xback + number) minus xback gives me number again - I know that some code might be redundant in the first part but it's working and it's easy to spot mistakes that way.

Craig, I don't quite get the wait function you suggest. How does it register that you clicked twice?, And do I have to put the wait into the script?, cause this might pose a problem.

best regards
James

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6069
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: UserInput Mouseup and Doublemouseup

Post by dunbarx » Sat Sep 10, 2011 9:04 pm

James.

Try the script in a button.

By the way, is it clearer if I had written:

if the mouseClick is "true" then...

Anyway, now that you see that it works, the mechanics should be clear. The mouseClick is a function that returns either "true" or "false". This is detected by the engine during the wait period. So when the wait times out, this function determines which of the two forks the "if" construct is to take. The 20 is up to you.

I have not seen your script, but it should not be hard to include your functionality, of whatever complexity, into the commented lines (doSingleStuff, doDoubleStuff)

Craig Newman

JamesWebster
Posts: 25
Joined: Sun Aug 07, 2011 11:36 am

Re: UserInput Mouseup and Doublemouseup

Post by JamesWebster » Sun Sep 11, 2011 1:03 pm

Hey Craig,

Code: Select all

On MouseUp
wait 20
If the Mouseclick is true then
put "mismatch" into Antwort #double click
answer "doubleclick"
Else
put "match" into Antwort #click
answer "click"
End if
end MouseUp
This works only on a limited basis - If I don't input anything, it still answers "click" even though it's not supposed to do anything.
Generally the script looks like this:

Code: Select all

On preopencard
--do stuff, create an array of letters
send "nbacktiming" to me in 10 millisec
end preopencard
On Mouseup
-currently the script above
end Mouseup
On nbacktiming
If number of repeats hasn't reached the limit
--do stuff (show a letter)
Mouseup --to get the user input
If letter does match the criterion and the userinput correctly says wether the letter matches the criterion 
Else
add 1 to error
End if
send "clearfield" to me in 500 millisec
send "nbacktiming" to me in 3000 millisec
Else
go to another card
End if
End nbacktiming
on clearfield
put "" into field "letter"
end clearfield
Any way that the general structure of the script influences the behaviour of your HC method?,
and any advice on how to fix this?

best regards
James

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6069
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: UserInput Mouseup and Doublemouseup

Post by dunbarx » Sun Sep 11, 2011 8:19 pm

James.

You are calling a handler (nBackTiming), and placing a "mouseUp" call within that handler. There is no opportunity for the "if" structure to help you, because you are calling the handler without anyone ever clicking anywhere. It might be possible to actually click the mouse during the wait period, but nobody would ever know this was an option. Try it. Set the cursor to something during the wait period, so you will know it is time to act, and jump in and click.

This all compiles correctly, but is not functional. You are doing it sort of backwards.

Use the mouseUp handler to start your process, not the "preOpencard" handler. Or, if you like, put up an answer dialog with two choices in your "nBackTiming" handler instead of trying to use the click/doubelClick thing at all.

But the point is that the trick is only valid if you actually click (or doubleClick). It is intimately tied to that simple action, and you have buried it in a processing script.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6716
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by FourthWorld » Sun Sep 11, 2011 9:02 pm

I would suggest using two different buttons, for cognitive reasons.

Short explanation:
http://lists.runrev.com/pipermail/use-l ... 52549.html

Longer explanation:
http://lists.runrev.com/pipermail/use-l ... 52534.html
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Fri Nov 08, 2013 12:17 am

Great code dunbarx!
Interesting explanation FourthWorld.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”