Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Elwood
Newbie


Joined: 26 Aug 2011
Posts: 4

PostPosted: Fri Aug 26, 2011 5:10 am   

How to stop a running script?
 
I have a button that runs a script to equip my character, for example:

#SEND "wear shoes"
#WAIT 5000
#SEND "wear jacket"
#WAIT 5000
#SEND "wear hat"
#WAIT 5000
#SEND "wear scarf"

But let's say in the middle of the script, right after I wear the jacket during that 5000 ms wait, I want to stop the script.

How can I do that?
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Fri Aug 26, 2011 6:47 am   
 
I think you want #ABORT.
_________________
.geniusclown
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Aug 26, 2011 1:24 pm   
 
More likely you need the #STOP command. '#STOP threadid' will stop the thread with id threadid.
Reply with quote
Elwood
Newbie


Joined: 26 Aug 2011
Posts: 4

PostPosted: Fri Aug 26, 2011 6:36 pm   
 
How do I set the thread ID of the button's script? I've tried to use #thread and #stop before, but couldn't get it to work. Would you please write out a short example of how the commands work?

Thanks for any help you can provide.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Fri Aug 26, 2011 8:06 pm   
 
This is the way I've done it in the past. If you added
Code:
#th ID
to the beginning of a script, where ID would be some unique name. Then while that script was running if you typed
Code:
#stop ID
on the command line while that script was running it would be aborted.

Here is the script you posted where I have put it in an alias named test and gave it's thread an ID named test.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="test" copy="yes">
    <value>#th test
#SEND "wear shoes"
#WAIT 5000
#SEND "wear jacket"
#WAIT 5000
#SEND "wear hat"
#WAIT 5000
#SEND "wear scarf" </value>
  </alias>
</cmud>


Typing test will start the script. Then if at any time you wanted to stop the script you would type #stop test on the command line or execute it from another setting and the script would be aborted.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Fri Aug 26, 2011 10:23 pm   
 
Even better. I didn't realize that functionality was added to the #STOP command.
_________________
.geniusclown
Reply with quote
Elwood
Newbie


Joined: 26 Aug 2011
Posts: 4

PostPosted: Sat Aug 27, 2011 6:26 am   
 
I've tried that, but I can't seem to get it to work... Here is my button XML:

<button autopos="false" left="550" priority="1580" id="158">
<caption>test</caption>
<value>#th test
#echo 1
#wait 5000
#echo 2
#wait 5000
#echo 3
#wait 5000
#echo 4
#wait 5000
#echo 5
#wait 5000
#echo 6 </value>
</button>

But "#stop test" doesn't seem to do anything.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sat Aug 27, 2011 2:35 pm   
 
It looks like threads of scripts run from a button aren't being tracked for some reason. In the test class below I have a macro, alias and your button. The actual script is contained in the alias. Enter the alias on the command line then use #TH and a thread with an id of test shows up and is tracked. Press F5 and the macro calls the alias which you can then use #TH and see a thread with an ID of test shows up and is tracked. Now press your button which call the same alias that the macro called and we entered directly that kept track of the test thread and if you use #TH nothing is shown.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="ThreadTest" copy="yes">
    <button autopos="false" left="550" priority="1580" copy="yes">
      <caption>test</caption>
      <value>test1</value>
    </button>
    <alias name="test1" copy="yes">
      <value>#th test
#echo 1
#wait 5000
#echo 2
#wait 5000
#echo 3
#wait 5000
#echo 4
#wait 5000
#echo 5
#wait 5000
#echo 6</value>
    </alias>
    <macro key="F5" copy="yes">
      <value>test1</value>
    </macro>
  </class>
</cmud>


Now if you go into the button and change the script to
Code:
#exec test1
the thread can be seen using the #TH command and you can #stop #suspend or #resume it as needed. This sounds kind of buggy maybe? Everything can be tested in the untitled session with the class above and the change I just spoke of. Maybe Zugg can have a look at this and see if something can be done to make the actual script usable in the button rather than needing to create an alias and #exec it from the button. Either way there's your fix for now. Put the script in an alias the #exec the alias from the button.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4772
Location: Pensacola, FL, USA

PostPosted: Sun Aug 28, 2011 1:06 am   
 
try having the button call an alias with the same code?
_________________
Discord: Shalimarwildcat
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sun Aug 28, 2011 2:20 am   
 
shalimar wrote:
try having the button call an alias with the same code?


Yes, it seems you need to use #exec aliasname in the button, if you want to name the thread that is created by a script when a button is pushed. Aliasname would be an alias that actually names the thread and contains the script. That's why I said it seems kind of buggy. Seems like you should be able to name the thread in the button, enter the script and be done with it.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Elwood
Newbie


Joined: 26 Aug 2011
Posts: 4

PostPosted: Sun Aug 28, 2011 7:47 pm   
 
Having the button call the alias works for me. Thanks a lot for the help.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4772
Location: Pensacola, FL, USA

PostPosted: Mon Aug 29, 2011 7:07 am   
 
optionally, you could make the button do
Code:
#IF (%threadid(threadName)) {#STOP threadName} {
#EXEC aliasName
}
to do everything with the same click
_________________
Discord: Shalimarwildcat
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net