Execution halts without user prompt
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 92
- Joined: Thu Feb 14, 2013 7:17 pm
Execution halts without user prompt
I'm pretty excited about Livecode. I'm not far from completing my App and I've never programmed anything before. The examples and tutorials are very thorough which helps a lot.
However I have a problem I just can't solve, I'm sure there is a simple answer.
I have a card that essentially gathers information including taking a photo and then puts it all into an email to send. My code works great and I'm happy with it except that without a user prompt just before "iphoneComposeMail tSubject, tTo,,, tBody, tAttachment", the execution just freezes and the email doesn't generate. If I add in: answer "Email the report?" with "Yes" or "No" just before the iphoneComposeMail line, then regardless of what is answered the email is created and all is good. As soon as I comment out the user prompt the code freezes? The thing is I would rather not have this extra user prompt.
code: (line needed for code to execute properly is in red)
on mouseUp
--first we put the sensor readings for lat, long, time into variables
put mobileSensorReading("Location",true) into tLocation
put tLocation["latitude"] into tLat
put tLocation["longitude"] into tLong
put tLocation["timestamp"] into tStamp
--then we convert the time in seconds to date and time
convert tStamp to short date and long time
--now we ask the user to describe the place and hazard
ask "What is the hazard?"
put it into tHazard
ask "Location of the hazard?"
put it into tPlace
--now we get a photo
set the lockloc of the templateimage to true
set the width of the templateimage to "320"
set the height of the templateimage to "320"
set the left of the templateimage to "165"
set the top of the templateimage to "377"
mobilepickphoto "library"
put the last image into tAttachment["data"]
put "hazard.jpg" into tAttachment["name"]
--now we create our fields for the email send
put "sample@sample.com" into tTo
put "Test Report" into tSubject
put "The following has been reported: " && tHazard && "at" && tPlace into tHazard2
put tHazard2 && " LATITUDE:" && tLat && " LONGITUDE:" && tLong && " DATE/TIME:" && tStamp into tBody
-- now we send the email
answer "Email the report?" with "Yes" or "No"
iphoneComposeMail tSubject, tTo,,, tBody, tAttachment
put the result into tresult
switch tresult
case "failed"
answer information "Email not sent. Please try again!"
break
case "saved"
answer information "Email saved as draft. Please send."
break
case "cancel"
answer information "Operation cancelled. Report not sent."
break
default
--now we populate the data box
put tBody into fld "Body"
end switch
end mouseUp
However I have a problem I just can't solve, I'm sure there is a simple answer.
I have a card that essentially gathers information including taking a photo and then puts it all into an email to send. My code works great and I'm happy with it except that without a user prompt just before "iphoneComposeMail tSubject, tTo,,, tBody, tAttachment", the execution just freezes and the email doesn't generate. If I add in: answer "Email the report?" with "Yes" or "No" just before the iphoneComposeMail line, then regardless of what is answered the email is created and all is good. As soon as I comment out the user prompt the code freezes? The thing is I would rather not have this extra user prompt.
code: (line needed for code to execute properly is in red)
on mouseUp
--first we put the sensor readings for lat, long, time into variables
put mobileSensorReading("Location",true) into tLocation
put tLocation["latitude"] into tLat
put tLocation["longitude"] into tLong
put tLocation["timestamp"] into tStamp
--then we convert the time in seconds to date and time
convert tStamp to short date and long time
--now we ask the user to describe the place and hazard
ask "What is the hazard?"
put it into tHazard
ask "Location of the hazard?"
put it into tPlace
--now we get a photo
set the lockloc of the templateimage to true
set the width of the templateimage to "320"
set the height of the templateimage to "320"
set the left of the templateimage to "165"
set the top of the templateimage to "377"
mobilepickphoto "library"
put the last image into tAttachment["data"]
put "hazard.jpg" into tAttachment["name"]
--now we create our fields for the email send
put "sample@sample.com" into tTo
put "Test Report" into tSubject
put "The following has been reported: " && tHazard && "at" && tPlace into tHazard2
put tHazard2 && " LATITUDE:" && tLat && " LONGITUDE:" && tLong && " DATE/TIME:" && tStamp into tBody
-- now we send the email
answer "Email the report?" with "Yes" or "No"
iphoneComposeMail tSubject, tTo,,, tBody, tAttachment
put the result into tresult
switch tresult
case "failed"
answer information "Email not sent. Please try again!"
break
case "saved"
answer information "Email saved as draft. Please send."
break
case "cancel"
answer information "Operation cancelled. Report not sent."
break
default
--now we populate the data box
put tBody into fld "Body"
end switch
end mouseUp
Re: Execution halts without user prompt
Hi...
You are not dealing with the response from the answer dialog... try this
Dixie
You are not dealing with the response from the answer dialog... try this
Code: Select all
on mouseUp
/* your script up to this point */
answer "Email the report ?" with "Yes" or "No"
if it = "No" then
exit mouseUp
else
/*the rest of your script */
end if
end mouseUp
Re: Execution halts without user prompt
I hate to answer this question this way but maybe someone can tell me why it works.
Sometimes when running code it does not work unless I am stepping through the code using the debugger. The only difference I saw was that stepping through was slower... At the point where the code breaks if I put a "wait 1 tick" (like your answer dialog) the code then runs fine. I wouldn't even call this a workaround.
Simon
Sometimes when running code it does not work unless I am stepping through the code using the debugger. The only difference I saw was that stepping through was slower... At the point where the code breaks if I put a "wait 1 tick" (like your answer dialog) the code then runs fine. I wouldn't even call this a workaround.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Execution halts without user prompt
Try replacing the answer dialog code with a "wait 30 with messages".
Gerry
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.
Former LiveCode developer.
Now recovering.
-
- Posts: 92
- Joined: Thu Feb 14, 2013 7:17 pm
Re: Execution halts without user prompt
Dixie, the point was I wanted to remove the answer dialog. Simon, I tried your suggestion but it didn't work.
Gerry, thank you so much for "wait 30 with messages", everything works like a charm now. I'm not sure I understand why, but time to move on....
Adam
Gerry, thank you so much for "wait 30 with messages", everything works like a charm now. I'm not sure I understand why, but time to move on....
Adam
Re: Execution halts without user prompt
Sorry, I really must read posts more carefully... even though Gery Orkin has sorted your problem with 'wait 30 with messages... does 'wait 0 millisecs with messages' work... I just wonder how much time the engine is needing to catch up with itself...
Dixie
Dixie
-
- Posts: 92
- Joined: Thu Feb 14, 2013 7:17 pm
Re: Execution halts without user prompt
"wait 0 millisecs with messages" doesn't work, I'll stick with "wait 30 with messages"
Thanks everyone.
Thanks everyone.