Can't find handler error
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Can't find handler error
Hi there,
I've written a script to help me with my psychology experiments. Basically it takes a list of words held in a CSV file, randomises the order of them and then displays each word on screen for a short time. When it gets to the end of the list, it re-randomises them and then does it all over again 5 times. However, about midway through the final set it usually bugs out and says it can't find the "DisplayWords" handler, which is odd since it has been using that handler for about 360 words before that. It seems to happen fairly consistently at the 360th word. I can't find anything in the script that might make that happen - anyone have any ideas? I've included the relevant part of the script below. sStudyCondition is a variable that is set at the beginning dictating if the words are to be displayed once or 5 times over, and sStudywords will have had an 80 line CSV file placed in it with the words themselves. Any help would be much appreciated!
Greg
on opencard
if gStudyCondition is 1 then
put "" into gRandomLines
wait 1 seconds
DisplayWords
end opencard
on DisplayWords
put line gLineNumber of sStudyWords into sDisplayWord
if sDisplayWord is empty
then
CheckEnd
else
put sDisplayWord into field StudyWord1
show field StudyWord1
wait 1 seconds
put "" into field StudyWord1
wait 0.25 seconds
SelectWords
end if
end DisplayWords
On SelectWords
add 1 to gLineNumber
put gLineNumber into field "page"
DisplayWords
end SelectWords
On CheckEnd
add 1 to sStrengthCondition
If sStrengthCondition is 5 then
go to card "PauseCard"
else
put 1 into gLineNumber
sort lines of sStudyWords by random(the number of lines of sStudyWords)
DisplayWords
end if
end CheckEnd
I've written a script to help me with my psychology experiments. Basically it takes a list of words held in a CSV file, randomises the order of them and then displays each word on screen for a short time. When it gets to the end of the list, it re-randomises them and then does it all over again 5 times. However, about midway through the final set it usually bugs out and says it can't find the "DisplayWords" handler, which is odd since it has been using that handler for about 360 words before that. It seems to happen fairly consistently at the 360th word. I can't find anything in the script that might make that happen - anyone have any ideas? I've included the relevant part of the script below. sStudyCondition is a variable that is set at the beginning dictating if the words are to be displayed once or 5 times over, and sStudywords will have had an 80 line CSV file placed in it with the words themselves. Any help would be much appreciated!
Greg
on opencard
if gStudyCondition is 1 then
put "" into gRandomLines
wait 1 seconds
DisplayWords
end opencard
on DisplayWords
put line gLineNumber of sStudyWords into sDisplayWord
if sDisplayWord is empty
then
CheckEnd
else
put sDisplayWord into field StudyWord1
show field StudyWord1
wait 1 seconds
put "" into field StudyWord1
wait 0.25 seconds
SelectWords
end if
end DisplayWords
On SelectWords
add 1 to gLineNumber
put gLineNumber into field "page"
DisplayWords
end SelectWords
On CheckEnd
add 1 to sStrengthCondition
If sStrengthCondition is 5 then
go to card "PauseCard"
else
put 1 into gLineNumber
sort lines of sStudyWords by random(the number of lines of sStudyWords)
DisplayWords
end if
end CheckEnd
-
- VIP Livecode Opensource Backer
- Posts: 157
- Joined: Thu Jun 29, 2006 4:16 pm
Okay, below is the full script for that card. It's probably a bit clumsy since I haven't done too many of these yet! A little explanation...
getwords simply loads a list of 80 words into the local variable sStudyWords.
On opening the card, it sets up the file save path, runs getwords and then randomises the order of the words in the variable. It puts 1 into glinenumber and either 0 or 4 into a variable called sStrengthCondition depending on the state of gCondition, set on an earlier card. It then runs displaywords, which displays the 80 words one by one by using glinenumber and incrementing it by 1 each time, picking that line of sStudyWords. When it gets to the end, it increases sStrengthCondition by 1 and then checks to see if sStrengthCondition is 5. When it reaches 5 it should go to the next card.
Now the funny thing is, if sStrengthCondition STARTS at 4, the whole thing works fine. It displays the 80 words one after another, and then goes to the next card. If sStrengthCondition starts at 0, it works fine until the 360th word, at which point it displays the "can't find handler" error. I can't find any script reason why it would work 359 times and bug out on the 360th! I've included both the error and the script below.
Greg
Type Handler: can't find handler
Object Study List
Line DisplayWords
Hint DisplayWords
getwords simply loads a list of 80 words into the local variable sStudyWords.
On opening the card, it sets up the file save path, runs getwords and then randomises the order of the words in the variable. It puts 1 into glinenumber and either 0 or 4 into a variable called sStrengthCondition depending on the state of gCondition, set on an earlier card. It then runs displaywords, which displays the 80 words one by one by using glinenumber and incrementing it by 1 each time, picking that line of sStudyWords. When it gets to the end, it increases sStrengthCondition by 1 and then checks to see if sStrengthCondition is 5. When it reaches 5 it should go to the next card.
Now the funny thing is, if sStrengthCondition STARTS at 4, the whole thing works fine. It displays the 80 words one after another, and then goes to the next card. If sStrengthCondition starts at 0, it works fine until the 360th word, at which point it displays the "can't find handler" error. I can't find any script reason why it would work 359 times and bug out on the 360th! I've included both the error and the script below.
Greg
Type Handler: can't find handler
Object Study List
Line DisplayWords
Hint DisplayWords
Code: Select all
global gLineNumber, gCondition, gUserPath, gConditionType, gStudyCondition, gStudyType, gUserSpot, gRandomLines, gBlockType
local sStudyWords, sLineNumber, sUser, sDisplayword, sStrengthCondition
on getwords
if gCondition is 1 then
put URL ("file:" & systemGetBasePath() & "StudyList1w.csv") into sStudyWords
end if
if gCondition is 2 then
put URL ("file:" & systemGetBasePath() & "StudyList2w.csv") into sStudyWords
end if
end getwords
on preopencard
put 1 into gLineNumber
put gLineNumber into field "page"
getwords
sort lines of sStudyWords by random(the number of lines of sStudyWords)
put the cNumber of this stack & "-" & the cGender of this stack & "-" & the cAge of this stack into sUser
systemPathValidate "participants/"
put systemGetBasePath() & "participants/" & sUser & "-" & gConditionType & "-" & gStudyType & "-" & gBlockType & "-" & "StudyRatings" & ".csv" into gUserPath
put "" into field StudyWord1
end preopencard
on opencard
if gStudyCondition is 1 then
put 4 into sStrengthCondition
else
put 0 into sStrengthCondition
end if
put "" into gRandomLines
wait 1 seconds
DisplayWords
end opencard
on DisplayWords
put line gLineNumber of sStudyWords into sDisplayWord
if sDisplayWord is empty
then
CheckEnd
else
put sDisplayWord into field StudyWord1
show field StudyWord1
wait 1 seconds
put "" into field StudyWord1
wait 0.25 seconds
SelectWords
end if
end DisplayWords
On SelectWords
add 1 to gLineNumber
put gLineNumber into field "page"
DisplayWords
end SelectWords
On CheckEnd
add 1 to sStrengthCondition
If sStrengthCondition is 5 then
go to card "PauseCard"
else
put 1 into gLineNumber
getwords
sort lines of sStudyWords by random(the number of lines of sStudyWords)
DisplayWords
end if
end CheckEnd
-
- VIP Livecode Opensource Backer
- Posts: 157
- Joined: Thu Jun 29, 2006 4:16 pm
Can't find handler error
I don't see anything that jumps out as a problem with your scripts. I have some time next week and I'd be happy to look at the stack if you'd like to send it.
One more thought -- have you tried putting all your handlers in the stack script rather than the card -- then all cards can see the handlers.
One more thought -- have you tried putting all your handlers in the stack script rather than the card -- then all cards can see the handlers.
Kinda sorted
Thanks for the generous offer! However I've solved it by changing how it was programmed now - instead of having a count that goes up one by one I've used a repeat until command and that seems to have solved it.
I will keep your advice in mind for next time though - I'm always running new experiments so I may well run into the same problem again. I can only think it was some strange memory problem, but since it works now I'm not too worried about tracking it down.
Thanks for everyone's advice - it was all much appreciated.
I will keep your advice in mind for next time though - I'm always running new experiments so I may well run into the same problem again. I can only think it was some strange memory problem, but since it works now I'm not too worried about tracking it down.
Thanks for everyone's advice - it was all much appreciated.
Re: Can't find handler error
Hi guys,
I'm developing a code library that can be reused in any card and stack. There are 1 stack and 1 substack, just for you have more understand what I'm doing
*Stack is Application
-Test card : there is 1 button to select record into datagrid
*substack is MyLibrary
-DBConnection card : there are 3 command
-openConnection
-CloseConnection
-ConvertCursortoArray
My problem is not able to call ConvertCursortoArray but I can call openConnection.
I have try to fix but It doesn't help.Hope you guys can help me
Here is my code
*substack
#################################################################################################################################
on openConnection
-- use a global variable to hold the connection ID so other scripts can use it
global gConnectionID
-- set up the connection parameters - edit these to suit your database
put "localhost" into tDatabaseAddress
put "quangtemp" into tDatabaseName
put "root" into tDatabaseUser
put "1234567" into tDatabasePassword
-- connect to the database
put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
if tResult is a number then
put tResult into gConnectionID
#answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID
else
put empty into gConnectionID
answer error "Unable to connect to the database:" & cr & tResult
end if
end openConnection
#################################################################################################
on closeConnection
global gConnectionID
-- if we have a connection, close it and clear the global connection ID
if gConnectionID is a number then
revCloseDatabase gConnectionID
put empty into gConnectionID
end if
end closeConnection
##################################################################################################
public command ConvertSQLCursorToArray pCursor, @pOutArrayA
local i
local theFields
local theError
## Get the names of all the columns in the database cursor
put revDatabaseColumnNames(pCursor) into theFields
if theFields begins with "revdberr," then
put item 2 to -1 of theFields into theError
end if
if theError is empty then
put 0 into i
## Loop through all rows in cursor
repeat until revQueryIsAtEnd(pCursor)
add 1 to i
## Move all fields in row into next dimension of the array
repeat for each item theField in theFields
put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[ theField ]
end repeat
revMoveToNextRecord pCursor
end repeat
end if
return theError
end ConvertSQLCursorToArray
################################################################################################
* myStack Application
on mouseUp
call openConnection of card "DBConnection" of stack "Mysubstack"
global gConnectionID
if gConnectionID is a integer then
## Query the database for data
put revQueryDatabase( gConnectionID, "call test1()") into theCursor
if theCursor is an integer then
call ConvertSQLCursorToArray theCursor, theDataGridArray ======================PROBLEM IS HERE "CAN"T FIND HANDLER ERROR==============
put the result into theError
if theError is empty then
set the dgData of group "DataGrid 1" to theDataGridArray
#put the dgIndexes of group "DataGrid 1" into theIndexes
put the dgNumberOfLines of group "DataGrid 1" into Totalrows --tong so dong co trong datagrid
#answer Totalrows
end if
## Close the database cursor
revCloseCursor theCursor
end if
## Close the database connection
revCloseDatabase gConnectionID
else
answer "Error connecting to the database:" && gConnectionID & "."
end if
end mouseUp
I'm so appreciated for your help
Quang
I'm developing a code library that can be reused in any card and stack. There are 1 stack and 1 substack, just for you have more understand what I'm doing

*Stack is Application
-Test card : there is 1 button to select record into datagrid
*substack is MyLibrary
-DBConnection card : there are 3 command
-openConnection
-CloseConnection
-ConvertCursortoArray
My problem is not able to call ConvertCursortoArray but I can call openConnection.
I have try to fix but It doesn't help.Hope you guys can help me
Here is my code
*substack
#################################################################################################################################
on openConnection
-- use a global variable to hold the connection ID so other scripts can use it
global gConnectionID
-- set up the connection parameters - edit these to suit your database
put "localhost" into tDatabaseAddress
put "quangtemp" into tDatabaseName
put "root" into tDatabaseUser
put "1234567" into tDatabasePassword
-- connect to the database
put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
if tResult is a number then
put tResult into gConnectionID
#answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID
else
put empty into gConnectionID
answer error "Unable to connect to the database:" & cr & tResult
end if
end openConnection
#################################################################################################
on closeConnection
global gConnectionID
-- if we have a connection, close it and clear the global connection ID
if gConnectionID is a number then
revCloseDatabase gConnectionID
put empty into gConnectionID
end if
end closeConnection
##################################################################################################
public command ConvertSQLCursorToArray pCursor, @pOutArrayA
local i
local theFields
local theError
## Get the names of all the columns in the database cursor
put revDatabaseColumnNames(pCursor) into theFields
if theFields begins with "revdberr," then
put item 2 to -1 of theFields into theError
end if
if theError is empty then
put 0 into i
## Loop through all rows in cursor
repeat until revQueryIsAtEnd(pCursor)
add 1 to i
## Move all fields in row into next dimension of the array
repeat for each item theField in theFields
put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[ theField ]
end repeat
revMoveToNextRecord pCursor
end repeat
end if
return theError
end ConvertSQLCursorToArray
################################################################################################
* myStack Application
on mouseUp
call openConnection of card "DBConnection" of stack "Mysubstack"
global gConnectionID
if gConnectionID is a integer then
## Query the database for data
put revQueryDatabase( gConnectionID, "call test1()") into theCursor
if theCursor is an integer then
call ConvertSQLCursorToArray theCursor, theDataGridArray ======================PROBLEM IS HERE "CAN"T FIND HANDLER ERROR==============
put the result into theError
if theError is empty then
set the dgData of group "DataGrid 1" to theDataGridArray
#put the dgIndexes of group "DataGrid 1" into theIndexes
put the dgNumberOfLines of group "DataGrid 1" into Totalrows --tong so dong co trong datagrid
#answer Totalrows
end if
## Close the database cursor
revCloseCursor theCursor
end if
## Close the database connection
revCloseDatabase gConnectionID
else
answer "Error connecting to the database:" && gConnectionID & "."
end if
end mouseUp
I'm so appreciated for your help
Quang