Can't Find Handler (All of a sudden)

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Can't Find Handler (All of a sudden)

Post by stephenmcnutt » Wed Mar 26, 2008 2:25 am

My script started telling me tonight that it "can't find handler" for one of my custom handlers. The thing is, the handler it's looking for is just a dozen or so lines farther down in the same script. It's been working fine until this evening. I was making some changes in this script, but nothing having to do with this handler.

Can you think of some common reasons why a script might stop being able to find a handler like this?

My first thought was that I somehow inadvertently damaged the handler, but it seems to still be properly formatted. The indenting still looks right between the "on" and "end" lines of the custom handler. Also, I recopied and pasted the handler's name to where it's being called, so I know it's not a typo.

ChristopherBodell
Posts: 52
Joined: Sun Jan 20, 2008 7:06 am

I've had this problem

Post by ChristopherBodell » Wed Mar 26, 2008 6:49 pm

Hi Stephen,

I've had this problem before, is the handler just there as an "on" handler, or is it a function or getProp, because if thats what it is then you might have to put the handler a little higher up the hierarchy.

To do this you can either insert the script of card "main_card" into front, with the script on it, be becarefull so that it dont interfere with other common handlers. Or you can start using stack "stack_name" with the function or handler in the script of that stack.

Also, another thing, depending on how you are going about calling your handler might be the problem cause you mentioned that it used to work fine...... You might not have it returning any data that you may need, or it could just be running into some knid of error. There's a lot of things that can be the case.

If you dont mind, post your code, or an example of your code and i can probably help you more.


Christopher Bodell

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Post by malte » Wed Mar 26, 2008 8:32 pm

Hi Steven,
do you use the handler as a command or do you use send?
Do you have a pass in the handler.

all the best,

Malte

stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Post by stephenmcnutt » Thu Mar 27, 2008 12:13 am

Thanks for the help, Christopher and Malte. Here's the code. The custom handler that's giving me the "can't find handler" error is the one called findAvailableDigits. It was working absolutely fine until yesterday, like I said:

on setSpaceValues -- Assigns a value 1-9 to each of the 81 spaces.
-- This section loads the array called subsquares, which has 9 elements, subsquares[1] through subsquares[9], each of which has 9 items, which are the space numbers of the 9 spaces in that subsquare.
local upperLefts
put 1 into item 1 of upperLefts
put 4 into item 2 of upperLefts
put 7 into item 3 of upperLefts
put 28 into item 4 of upperLefts
put 31 into item 5 of upperLefts
put 34 into item 6 of upperLefts
put 55 into item 7 of upperLefts
put 58 into item 8 of upperLefts
put 61 into item 9 of upperLefts
local incrementsToTheOtherEightSpaces
put 0 into item 1 of incrementsToTheOtherEightSpaces
put 1 into item 2 of incrementsToTheOtherEightSpaces
put 2 into item 3 of incrementsToTheOtherEightSpaces
put 9 into item 4 of incrementsToTheOtherEightSpaces
put 10 into item 5 of incrementsToTheOtherEightSpaces
put 11 into item 6 of incrementsToTheOtherEightSpaces
put 18 into item 7 of incrementsToTheOtherEightSpaces
put 19 into item 8 of incrementsToTheOtherEightSpaces
put 20 into item 9 of incrementsToTheOtherEightSpaces
global subsquares
local elementCounter
put 0 into elementCounter
local itemCounter
repeat for each item ul in upperLefts
add 1 to elementCounter
put 0 into itemCounter
repeat for each item i in incrementsToTheOtherEightSpaces
add 1 to itemCounter
put ul + i into item itemCounter of subsquares[elementCounter]
end repeat
end repeat
local theDigit
local chosenItem
global whichSpace
put 1 into whichSpace
repeat while whichSpace < 82
findAvailableDigits
if availableDigits = "" then
setSpaceValues
else
put the random of the number of items in availableDigits into chosenItem
put item chosenItem of availableDigits into theDigit
put theDigit into Spaces[whichSpace,1]
--set the icon of button ("space" & whichSpace) to (12000 + theDigit)
add 1 to whichSpace
end if
end repeat
end setSpaceValues

on findAvailableDigits
global availableDigits
repeat with n = 1 to 9
put n into item n of availableDigits
end repeat
-- Identify which subsquare whichSpace belongs to.
global subsquares
local whichSubsquare
global whichSpace
put 1 into whichSubsquare
repeat for each element e in subsquares
if whichSpace is among the items of e then
exit repeat
else
add 1 to whichSubsquare
end if
end repeat -- Now whichSubsquare contains the element number of the array subsquares[] that contains whichSpace.
-- Identify first (left) space in whichSpace's row.
local firstSpaceInRow
local firstSpaceInColumn
if whichSpace mod 9 = 0 then
put whichSpace - 8 into firstSpaceInRow
else
put whichSpace - (whichspace mod 9) + 1 into firstSpaceInRow
end if
-- Identify first (top) space in whichSpace's column.
if whichSpace mod 9 = 0 then
put 9 into firstSpaceInColumn
else
put whichSpace mod 9 into firstSpaceInColumn
end if
-- Delete inelligible digits from availableDigits. First load inelligible digits into the variable "markedForRemoval" to avoid altering availableDigits variable during iterrations of "repeat for each item" loops, which would cause errors.
local markedForRemoval
local i
put 1 into i
repeat for each item thisAvailableDigit in availableDigits
-- Identify digits already used in 3x3 subsquare.
repeat for each item spaceNumber in subsquares[whichSubsquare]
if thisAvailableDigit = Spaces[spaceNumber,1] then
if thisAvailableDigit is not among the items of markedForRemoval then
put thisAvailableDigit into item i of markedForRemoval
add 1 to i
end if
exit repeat
end if
end repeat
-- Identify digits already used in row.
repeat with n = 0 to 8
if thisAvailableDigit = Spaces[firstSpaceInRow + n,1] then
if thisAvailableDigit is not among the items of markedForRemoval then
put thisAvailableDigit into item i of markedForRemoval
add 1 to i
end if
exit repeat
end if
end repeat
-- Identify digits already used in column.
repeat with n = 0 to 8
if thisAvailableDigit = Spaces[firstSpaceInColumn + 9*n,1] then
if thisAvailableDigit is not among the items of markedForRemoval then
put thisAvailableDigit into item i of markedForRemoval
add 1 to i
end if
exit repeat
end if
end repeat
add 1 to itemNumber
end repeat
-- Delete items from availableDigits that are also in itemsMarkedForDelete.
repeat for each item thisMarkedItem in markedForRemoval
local thisItemNumber
put 1 into thisItemNumber
repeat for each item thisAvailableItem in availableDigits
if thisAvailableItem = thisMarkedItem then
delete item thisItemNumber of availableDigits
exit repeat
else
add 1 to thisItemNumber -- Only increment thisItemNumber if an item hasn't been deleted. If an item has been deleted, the item numbers of all subsequent items in availableDigits is decreased by one, so the next item in the list now has the item number of the just deleted item.
end if
end repeat
end repeat
end findAvailableDigits -- Now all remaining items in the variable availableDigits are the available digits for whichSpace.

ChristopherBodell
Posts: 52
Joined: Sun Jan 20, 2008 7:06 am

Ok...

Post by ChristopherBodell » Thu Mar 27, 2008 1:26 am

Hi Stephen,

first, just a quick tip, if you wnat to clean up the script a bit, shorten it, then you can put all the local variables on a single line & the globals all on a single line.....

global var1,var2,var3
local var1,var2,var3

Just an idea....

Anyway... So i looked at the script and it all looks fine, but what is the exact details of the error message? Is it hiliting a certain line in your script, if so, what is the line?

Another Idea...

Your "findAvailableDigits" handler, you could turn into a function.

function finAvailableDigits
script here
return SomeValue
end findAvailableDigits

You could make it return the contents of the "availableDigits" variable, and from the script, you could just check if "findAvailableDigits()" returns empty or not.... Just an idea


Christopher Bodell

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Thu Mar 27, 2008 1:35 am

Rev's error reporting, to put it lightly, sucks bog donkey balls.

The actual problem is most likely a scripting error in the handler findAviableDigits. For me these are normally typos, or wrong assumptions of variable contents. As you seem to juggle with lots of variables, I suggest to check your code for arrays that you assume are not arrays, and vice versa.

To find the Problem, try to put the relevant code into a teststack with no other code, set up fake test variables, and put it all into a build in message, for example in a mouseUp of a button. Rev's errors are often more specific if they are not in a handler that gets called by some other handlers.

Sorry that I can't give you a more specific hint, but i guess you understand that i don't want to look into every detail of your code to find the exact problem with it.

Also watch out, I assume (from looking at you code), that you don't know that arrays do not retain their ordering when one asks them about their contents. so the "keys" or "repeat for each <element/key>" will not be in the same ordering all the time, it'll be ordered by some internal memory management prerequisite instead.

Another hint, from looking at your code. When you use "repeat for each <whatever>" then it's most often best to not put stuff into <whatever> of any variable. the "repeat for each" form is very, very, very fast. But it's only so fast because it doesn't need to look at every <whatever> in the original variable, so when you use it to put stuff into another <whatever> of a variable, then a runrev-fairy dies every time. The best usage of repeat for each is "put after", a silly example:

Code: Select all

on mouseUp
  put "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" into theChars
  repeat for each item theItem in theChars
    if chartonum(theItem) mod 2 = 0 then
      put theChar & comma after listOfChars
    end if
  end repeat
  delete char -1 of listOfChars --get rid of last comma
  put listOfChars
end mouseUp
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Post by stephenmcnutt » Thu Mar 27, 2008 1:40 am

Thanks a bunch, Christopher. I like your idea of turning findAvailableDigits into a function.

I ran the thing in debug mode with the variable watcher, and it turns out it DOES find the findAvailableDigits handler the first bunch of times UNTIL the condition "if availableDigits = "" " turns out to be true, at which point it is supposed to start itself over and try again. However, after that time, it can never find the findAvailableDigits handler again.

The exact error message just says it can't find the handler. The hint is: findAvailableDigits.

ChristopherBodell
Posts: 52
Joined: Sun Jan 20, 2008 7:06 am

ok...

Post by ChristopherBodell » Thu Mar 27, 2008 2:48 am

yeah, that's where i would turn it into a function so you can see if the data that is returned by the function is empty or not, it's much easier for me if i do it that way.... That would be the ideal thing to do though, if you dont know how to write functions then i can help you with that too, but i assume you already do seeing as how you thought it would be a good idea yourself.

Christopher Bodell

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Mar 27, 2008 3:28 am

Hi stephenmcnutt,

I ran your handler and don't get any errors. Do I need to do anything specific to get the error?

Please post the error message. It should tell us at which point things go wrong.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

ChristopherBodell
Posts: 52
Joined: Sun Jan 20, 2008 7:06 am

Hi Mark

Post by ChristopherBodell » Thu Mar 27, 2008 4:14 am

Hi Mark,


Not to sound rude or anything but he already posted the error, It's just "Can't find handler" and the hint is the "fintAvailableDigits"

He says it works fine the first few times, until it comes to (if avaiableDigits = " ") condition, it must be some kind of comiling error after that..... I didn't have the time to test the handler myself.....


Christopher Bodell

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Mar 27, 2008 9:34 am

Hi Christopher,

The typos in "fintAvailableDigits" and "avaiableDigits" are sufficient reason to encounter an error and that's why I asked stephenmcnutt to post the exact error here. It would be best if he copied it from the error dialog window and pasted it here.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Talking LiveCode”