Execution halts without user prompt

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jekyllandhyde
Posts: 92
Joined: Thu Feb 14, 2013 7:17 pm

Execution halts without user prompt

Post by jekyllandhyde » Thu Feb 28, 2013 8:56 pm

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

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Execution halts without user prompt

Post by Dixie » Thu Feb 28, 2013 10:29 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Execution halts without user prompt

Post by Simon » Thu Feb 28, 2013 11:06 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Execution halts without user prompt

Post by Jellicle » Thu Feb 28, 2013 11:27 pm

Try replacing the answer dialog code with a "wait 30 with messages".

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

jekyllandhyde
Posts: 92
Joined: Thu Feb 14, 2013 7:17 pm

Re: Execution halts without user prompt

Post by jekyllandhyde » Thu Feb 28, 2013 11:52 pm

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

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Execution halts without user prompt

Post by Dixie » Fri Mar 01, 2013 12:11 am

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

jekyllandhyde
Posts: 92
Joined: Thu Feb 14, 2013 7:17 pm

Re: Execution halts without user prompt

Post by jekyllandhyde » Mon Mar 04, 2013 7:30 pm

"wait 0 millisecs with messages" doesn't work, I'll stick with "wait 30 with messages"

Thanks everyone.

Post Reply