Page 1 of 1

Execution halts without user prompt

Posted: Thu Feb 28, 2013 8:56 pm
by jekyllandhyde
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

Re: Execution halts without user prompt

Posted: Thu Feb 28, 2013 10:29 pm
by Dixie
Hi...

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
Dixie

Re: Execution halts without user prompt

Posted: Thu Feb 28, 2013 11:06 pm
by Simon
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

Re: Execution halts without user prompt

Posted: Thu Feb 28, 2013 11:27 pm
by Jellicle
Try replacing the answer dialog code with a "wait 30 with messages".

Gerry

Re: Execution halts without user prompt

Posted: Thu Feb 28, 2013 11:52 pm
by jekyllandhyde
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

Re: Execution halts without user prompt

Posted: Fri Mar 01, 2013 12:11 am
by Dixie
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

Re: Execution halts without user prompt

Posted: Mon Mar 04, 2013 7:30 pm
by jekyllandhyde
"wait 0 millisecs with messages" doesn't work, I'll stick with "wait 30 with messages"

Thanks everyone.