"Type" issue?

Alex Tweedly alex at tweedly.net
Mon May 9 06:03:43 EDT 2005


John Ridge wrote:

>While playing around with numToChar and so on, I put the following silly
>script into a card. It is intended to substitute random characters for the
>one the user types into a text field on the card.
>
>function randomInRange lowerLimit,upperLimit
> return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
>end randomInRange
>
>on keyDown whichKey
>  put randomInRange (120, 150)into fakeKey
>  put numtoChar (fakeKey)into whichKey
>  put whichKey
> pass keyDown
>end keyDown
>
>Really silly, of course. As it stands, it simply displays the random
>character in the message box. But if I change "put whichKey" to "type
>whichKey", I get an error message - there is a problem with the function
>handler. I'm puzzled - there wasn't a problem with the function handler a
>moment ago. Why does the change from "put" to "type" generate one? Duh...
>  
>
Interesting - I hadn't noticed the "type" command before. The docs say

> Comments:
> The type command sends a rawKeyDown and rawKeyUp message to the 
> current card for each character typed.

and I wasn't sure what the relationship would be between rawKeyDown and 
keyDown.

I discovered that using type results in both a rawKeyDown and a keyDown 
for each character being "typed".

So in your case, you have an infinite loop - each keydown event causes a 
"type" event which cause both a rawkeydown and a keydown (as well as 
passing the keydown) - and that causes a "type" .......

still not sure why that sometime results in a "problem with function 
handler" - for me it did that one time out of three - the other twice I 
got stuck in infinite loop and couldn't break out.

-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.6 - Release Date: 06/05/2005



More information about the use-livecode mailing list