Button use while script is running
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Button use while script is running
I can't seem to be able to use the buttons that I programmed to stop a script from running. I have a certain script that runs numbers starting for example at 1 and going to 100 I have tried to create a button to stop the script from running when the player of the game desires. However, the button is only active when the script is not running the numbers. How can I fix this so that I can press the button to stop the script while its running?
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Button use while script is running
Make a start/stop button that starts on mouseUp a 'self-calling action' and stops it on mouseDown, simply by setting a true/false variable.
The mouseDown/mouseUp technique is here for me better than putting it in one of mouseDown or mouseUp, what is, of course, also an option.
Thus you give here to others, to LC or your OS or your additional buttons, 8 millisecs time to get clicks and receive messages after each of your repeats in a 'long' loop.
The mouseDown/mouseUp technique is here for me better than putting it in one of mouseDown or mouseUp, what is, of course, also an option.
Code: Select all
local iWantToStop=true
on mouseDown
put not iWantToStop into iWantToStop
end mouseDown
on mouseUp
if iWantToStop then exit mouseUp
else doAction 1
end mouseUp
on doAction x
if iWantToStop or x > 100 then exit doAction
put x into fld "numbers" -- test
add 1 to x; send "doAction x" to me in 8 millisecs -- or slower
end doAction
shiftLock happens
Re: Button use while script is running
Hi Bennet,
1. welcome to the forum!
2. I deleted your double posting!
Best
Klaus
1. welcome to the forum!
2. I deleted your double posting!
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9752
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Button use while script is running
Hi.
Can't you simply insert a line like this:
Assuming that your running handler is called "runningHandler". Oh, and you make a button "stopHandler"
Now this will use just a little overhead, but is compact and readable.
Craig
Can't you simply insert a line like this:
Code: Select all
if the mouseLoc is within the rect of btn "stopHandler" and the mouse is down the exit runningHandler
Now this will use just a little overhead, but is compact and readable.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Button use while script is running
Hi Craig.
You are twice polling the mouse. I bet that jacque will criticise you
Hermann
You are twice polling the mouse. I bet that jacque will criticise you
Hermann
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 9752
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Button use while script is running
Hermann.
Jacque is used to that.
I did warn of a slight bit of overhead, and besides, that sort of exploitation of the xTalk UI is so old fashioned, you have to love it.
Craig
Jacque is used to that.
I did warn of a slight bit of overhead, and besides, that sort of exploitation of the xTalk UI is so old fashioned, you have to love it.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Button use while script is running
I see I have trained an accomplice so the task of criticism is no longer only up to me.
However, I will mention that unless the mouse is down at the exact moment that line of script runs, it will fail. LC doesn't buffer mouse states.
However, I will mention that unless the mouse is down at the exact moment that line of script runs, it will fail. LC doesn't buffer mouse states.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9752
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Button use while script is running
All true, true.
(Sob)
I was led down the garden path by the 8 mS in the OP handler. Of course, it was a bit optimistic that would stick around.
Craig
(Sob)
I was led down the garden path by the 8 mS in the OP handler. Of course, it was a bit optimistic that would stick around.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Button use while script is running
Aw. Here Craig, have a tissue. And think of all the good work you've done in the forums. Wouldn't be the same without you.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9752
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Button use while script is running
HONK.
Thanks.
So now I would do the usual practice in these cases in a "stop" button, which is what the OP actually wanted. Of course, Hermann's solution could be easily extended to that button by simply making a global out of the local.
But what if there were other things pending? Then you would have to collect (with "the result") only those pendingMessages that pertained to this particular "send" command, and only cancel those.
Craig
Thanks.
So now I would do the usual practice in these cases in a "stop" button, which is what the OP actually wanted. Of course, Hermann's solution could be easily extended to that button by simply making a global out of the local.
Code: Select all
on mouseUp
repeat for each line thisMessageID in the pendingMessages
cancel item 1 of thisMessageID
end repeat
end mouseUp
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Button use while script is running
To cancel only some of the pendingMessages, l usually just do this:
Code: Select all
if "doAction" is in thisMessageID then
cancel item 1 of thisMessageID
end if
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9752
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Button use while script is running
Jacque.
Much nicer.
You know, I never actually looked carefully at a printout of the current pendingMessages, and never realized that the name of the handler attached to a "send" command was included in item 4 in each string. Makes sense of course.
I always just collected "the result" which gives item 1 alone.
Craig
Much nicer.
You know, I never actually looked carefully at a printout of the current pendingMessages, and never realized that the name of the handler attached to a "send" command was included in item 4 in each string. Makes sense of course.
I always just collected "the result" which gives item 1 alone.
Craig
Re: Button use while script is running
The problem is not that the start or stop button doesn't work, it's that I can't click anything on the stack "the other button to pause the script for enough time for an answer to be entered" while the script is active. it will let me use the button after the script has run its course, but I would like to be able to interactively work with the script while it's running. If this makes any sense, please reply and tell me how I can fix it.
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: Button use while script is running
Well, since you haven't posted the code we can only respond in general terms. So...
assuming you've got something like this
then changing the 'wait' line to
should allow other events to happen.
Then in your 'stop' button you should be able to cancel things.
assuming you've got something like this
Code: Select all
put 1 into x
repeat forever
put x into field numberField
wait 1 second
add 1 to x
end repeat
Code: Select all
wait 1 second with messages
Then in your 'stop' button you should be able to cancel things.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
-
- VIP Livecode Opensource Backer
- Posts: 9752
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Button use while script is running
Benneet.
Now I am not sure what you are asking.
Did you mean that you are navigating to another stack and want to halt that handler?
Now make another stack with two buttons in it. Arrange so you can see both stacks. Put this into the script of btn 1 (the stop button) :
Put this into the script of the other button ( the silly button):
Now when you start the random making process, you can mosey over to the other stack at your leisure and either place random numbers into line 3 of stack 1, or stop the random maker entirely.
Both are silly.
Craig
Now I am not sure what you are asking.
Did you mean that you are navigating to another stack and want to halt that handler?
Doesn't matter. Make a new stack with a button and a field. In the button script:k anything on the stack "the other button...
Code: Select all
global stopRandoms
on mouseUp
put "false" into stopRandoms
makeRandoms
end mouseUp
on makeRandoms
put random(999) into line 1 of fld 1
if stopRandoms is "false" then send "makeRandoms" to me in 30
end makeRandoms
Code: Select all
global stopRandoms
on mouseUp
put "true" into stopRandoms
end mouseUp
Code: Select all
on mouseUp
put random(999) into line 3 of fld 1 of stack "untitled 1"
end mouseUp
Both are silly.
Craig