Stoping and resuming code?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

dburdan
Posts: 104
Joined: Fri Jan 28, 2011 5:39 am

Stoping and resuming code?

Post by dburdan » Fri Feb 11, 2011 1:36 am

I have a complicated one here. I am wondering if you can pause code then play it. Or something to that effect. What I am trying to achieve:

Code: Select all

on BtnClick
   CheckValue
   :::PAUSE HERE:::
   Other code goes here after CheckValue has been ran.
end BtnClick

on CheckValue
   Blah Blah
   if BtnA then
     add 10 to score
   else
     add 50 to score
   end if
  :::Now go to the paused location and pick up from there.
end CheckValue
Does this make sense? I know you can't actually "pause" code but is there someway to accomplish this effect?
Thanks

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Stoping and resuming code?

Post by bn » Fri Feb 11, 2011 1:57 am

Hi dburdan,
Why would you want to pause?
The way you scripted it now 'CheckValue' will be executed before the BtnClick goes on. The pause is not necessary here. BtnClick will hit "CheckVaulue" and go to that handler and returns to where it left and continues.

If you want to pause a script for various reasons you can issue a wait xxx |seconds|ticks|milliseconds in a script
But beware, the wait command without 'with messages' will halt Livecode and your program becomes unresponsive.

The e.g. "wait 100 milliseconds with messages" will let livecode pause the execution but livecode is ready for input. e.g. a mouseClick. moving a window etc. and livcode can do its housekeeping.
Most often you would want to add a wait with messages in very long repeat loops. Wait 0 milliseconds with messages is sufficient to the let you interrupt a runaway repeat loop with command period.

If you want to pause for longer you should look into the "send myCommand to destination in 30 seconds" send in time -> dictionary or in the user guide the section on "5.9 TimerBasedMessaging"

Kind regards

Bernd

dburdan
Posts: 104
Joined: Fri Jan 28, 2011 5:39 am

Re: Stoping and resuming code?

Post by dburdan » Fri Feb 11, 2011 2:03 am

Thanks for your reply Bernd. Unfortunately, the "CheckValue" command makes a group visible where the user would input something. So when it makes it visble, it runs the code after "CheckValue" in BtnClick. If this isn't a good example I'll take a screen shot and send it to your email.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Stoping and resuming code?

Post by bn » Fri Feb 11, 2011 2:11 am

Hi dburdan,
then I would change the flow of the program. Make your buttons visible and wait for the user to click. The code in the buttons would then trigger the rest. Or I am not getting what you want.

If you just want to show the button you could use the "wait" statement; if you want user input you dont know when the user will click, so it would be better to break that up as I said above.

Kind regards

Bernd

dburdan
Posts: 104
Joined: Fri Jan 28, 2011 5:39 am

Re: Stoping and resuming code?

Post by dburdan » Fri Feb 11, 2011 2:16 am

What is your email? I will send you a link to a video screen capture so you can see an example. I don't want to post a video of all of my app and code since it is unreleased. Or if you feel better about this, just send me an email and I will reply. My email is in my sig.

Thanks

dburdan
Posts: 104
Joined: Fri Jan 28, 2011 5:39 am

Re: Stoping and resuming code?

Post by dburdan » Fri Feb 11, 2011 2:58 am

Ok, I sent it. Thank you so much for taking the time to help me with this!

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Stoping and resuming code?

Post by Danny » Sun Feb 13, 2011 12:40 am

Hey dburdan or bn, I actully have a similar question; I'm not sure if your orginal question was answered but how do I skip code? I'm trying to give users stars if they catch a certian number of balls. But I can't use the ADD code cause if they replay the level then it will just keep adding more and more stars. So what I want to do is, if they the get max of three stars then it will skip the code

dburdan
Posts: 104
Joined: Fri Jan 28, 2011 5:39 am

Re: Stoping and resuming code?

Post by dburdan » Sun Feb 13, 2011 12:54 am

Can you give a sample of your code so we can better see your issue?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Stoping and resuming code?

Post by bn » Sun Feb 13, 2011 12:55 am

Hi Danny,

couldn't you just use a variable and test if the result would be > 3 like

put myScore + 1 into myNewTestScore
if myNewTestScore < 3 then add 1 to myScore

or is it something else you want to do?

btw, dburdan's problem was a little different and very specific. So no real use of posting it.

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Stoping and resuming code?

Post by Danny » Sun Feb 13, 2011 1:06 am

I want to do something different. What my problem is, is if you are playing my game and you get two stars then you might want to play again to get three. If I just add it then the field on the other card will say 5 but there is a limit in my game of 75 total stars, so it would throw it off.

This is my code

The start button

Code: Select all

on Stars
   if fld "fBallsCaught" <= fld  "3stars" then 
      add 3 to fld "minApples" OF stack "Level Select"
    
      
      if fld "fBallsCaught" <= fld  "2stars" then 
         add 2 to fld "minApples" of stack "Level Select" 
       

         if fld "fBallsCaught" <= fld  "1stars" then 
            add 1 to fld "minApples" OF stack "Level Select"
        
            
         end if
      end if 
   end if 
end Stars

The replay button

Code: Select all

 on apples
    if fld "fBallsCaught" <= "3apple" then  
       subtract 3 from fld "minApples" OF stack "Level Select"
       
        if fld "fBallsCaught" <= "2apple" then  
       subtract 2 from fld "minApples" OF stack "Level Select"

 if fld "fBallsCaught" <= "1apple" then  
    subtract 1 from fld "minApples" OF stack "Level Select"
    
 end if 
end if 
end if 
end apples

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Stoping and resuming code?

Post by bn » Sun Feb 13, 2011 2:41 pm

Danny,

I dont understand very well what you are doing.

These are just some observations on you "apple" handler.

Code: Select all

on apples
       if fld "fBallsCaught" <= "3apple" then  
             subtract 3 from fld "minApples" 
             
              if fld "fBallsCaught" <= "2apple" then  
                subtract 2 from fld "minApples" 
         
         if fld "fBallsCaught" <= "1apple" then  
                subtract 1 from fld "minApples"
         end if 
      end if 
   end if 
end apples
You do a string compare and not a numeric compare on
if fld "fBallsCaught" <= "3apple"
if that is what you want you might get away with it but it is confusing.

if I enter 1apple into field "fBallsCaught" it subtracts 6 from field "minApples" is that what you want?

Or do you want to say

Code: Select all

 if fld "fBallsCaught" <= FIELD "3apple" then  
assuming you meas FIELD and FIELD "3apple" contains a number then you would do a numeric compare. But in your code you dont say FIELD.
But still you subtract 6 if 1 is in a field 1apple. I dont get it.
if you are playing my game and you get two stars then you might want to play again to get three. If I just add it then the field on the other card will say 5 but there is a limit in my game of 75 total stars, so it would throw it off.
I don't see where the stars come into play in your code. And since I don't know the game I have no idea how to help you except in the very generic way I did in the previous post.

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Stoping and resuming code?

Post by Danny » Sun Feb 13, 2011 5:04 pm

I understand that that last post is confusing and that my code is too. I've been doing a lot of tinkering and some times i just come up with something random for the field names. I think it would be best if I came up with an example program to post up here. Let me put that together and I'll repost when I'm done. Again sorry for the confusing post before it's a little bit tough to explain it over the internet. I will use you suggestions in my game.

Thanks,

Danny

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Stoping and resuming code?

Post by Danny » Sun Feb 13, 2011 11:21 pm

At long last here it is :D
Attachments
Example 1.livecode.zip
(2.13 KiB) Downloaded 282 times

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Stoping and resuming code?

Post by Danny » Sun Feb 13, 2011 11:21 pm

I was able to touch up some of the code. Thanks for taking the time to look at this.
Attachments
Example 2.livecode.zip
(2.37 KiB) Downloaded 313 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Stoping and resuming code?

Post by bn » Mon Feb 14, 2011 1:16 am

Hi Danny,

there was a flaw in your logic when adding: if you had 1 point it would add 3 because it met the condition for 3 and it added 2 because it also met the condition for 2 and added one rightfully so because it was supposed to. In the script I changed the logic. That was what I was talking about in my above post:
if I enter 1apple into field "fBallsCaught" it subtracts 6 from field "minApples" is that what you want?
I added a field that checks if 3 stars were ever reached and if so the handler Stars would be exited immediately.
Alternatively you can check if the counter in you card 4 stack has reached a certain limit. It is commented out in the scrip of the play button. (It still assumes you dont want more than 3 in the field "apples", you would have to change that)

But basically it shows you how to stop execution of a handler if a certain condition is met. There are more ways to do this but using a field or checking a value in a field is a good start.

Kind regards

Bernd
Attachments
Example 3.livecode.zip
(2.71 KiB) Downloaded 319 times

Post Reply