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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
complex
Apprentice


Joined: 12 Apr 2004
Posts: 134
Location: USA

PostPosted: Fri Oct 01, 2010 4:54 pm   

[3.29b] Unexplained freezing
 
I have a *beta* script designed to parse my inventory, and sell the items at the various shops. However when it comes time to dump the sell queue Cmud locks up for extended periods of time, and my CPU usage jumps to about 80%.

This is the script.
Code:

<class name="AutoSell" id="61">
  <class name="SellMatch" id="63">
    <trigger enabled="false" id="64">
      <pattern>(%d)*({@WeaponList})</pattern>
      <value>#LOOP %1 {SellQueue = %addItem(@SellWeaponCMD.%2,@SellQueue)}</value>
    </trigger>
    <trigger priority="780" id="78">
      <pattern>(%d)*({@ArmorList})</pattern>
      <value>#LOOP %1 {SellQueue = %addItem(@SellArmorCMD.%2,@SellQueue)}</value>
    </trigger>
    <trigger priority="780" enabled="false" id="84">
      <pattern>*({@ArmorList})</pattern>
      <value>SellQueue = %addItem(@SellArmorCMD.%1,@SellQueue)</value>
    </trigger>
  </class>
  <class name="CheckSellQueue" id="68">
    <alias name="EmptySellQueue" id="69">
      <value>#if (%countlist(@SellQueue)>0) {
%pop(SellQueue)
//#t- CheckSellQueue
}</value>
    </alias>
  </class>
  <class name="Lists" id="71">
    <var name="WeaponList" type="StringList" id="62">
      <value>a flail of the priestess</value>
      <json>["a flail of the priestess"]</json>
    </var>
    <var name="SellWeaponCmd" type="Record" id="65">
      <value>a flail of the priestess=sell flail</value>
      <json>{"a flail of the priestess":"sell flail"}</json>
    </var>
    <var name="SellArmorCmd" type="Record" id="74">
      <value>some furs=sell furs|a pendant of the dragon=sell pend|a dog collar=sell collar|a pair of tattered breeches=sell brea|some priestly vestments=sell vest</value>
      <json>{"some furs":"sell furs","a pendant of the dragon":"sell pend","a dog collar":"sell collar","a pair of tattered breeches":"sell brea","some priestly vestments":"sell vest"}</json>
    </var>
    <var name="ArmorList" type="StringList" id="75">
      <value>a dog collar|a pair of tattered breeches|a pendant of the dragon|some priestly vestments|some furs|a pair of metal shears</value>
      <json>["a dog collar","a pair of tattered breeches","a pendant of the dragon","some priestly vestments","some furs","a pair of metal shears"]</json>
    </var>
    <var name="SellQueue" type="StringList" id="86">
      <json>[]</json>
    </var>
  </class>
  <trigger priority="770" id="77">
    <pattern>You sell*</pattern>
    <value>#T+ CheckSellQueue
EmptySellQueue</value>
  </trigger>
  <alias name="sellarmor" id="79">
    <value>EmptySellQueue</value>
  </alias>
  <alias name="sellweapon" id="80">
    <value>
EmptySellQueue</value>
  </alias>
</class>



For testing I have all of my item matting triggers off except for the armor matching, and my inventory looks like this.
Code:


You are carrying:
(17) a pendant of the dragon
( 4) some priestly vestments



So I look in my inventory, and the trigger populates the SellQueue variable with 21 items, sell pend, sell pend, sell pend, ..., sell vest. Next I try to initiate the EmptySellQueue variable with the command sellarmor and that is where everything freezes up. The first item in the list is sent to the mud, and The responce is

Code:

You sell* ...


this triggers the next sell pend, and then cmud freezes for about 1.5 minuets. By freezes I mean that I can alt tab to and from Cmud, and work in other screens, but I can not interaction with Cmud in any way. I can no longer look at the debug screen, I can not click trigger off, I can not send input, its just frozen. After the minute and a half the there is a response of the next item being sold from the mud, and the trigger (you sell*) has EmptySellQueue pop the next item in the list, and again there is another pause of about a minute. While all of this is going on my Cmud is sucking up my CPU, about 50%, I have an 8400, its not the fastest, but Cmud should not be taking up so much resources.

http://www.imagebam.com/image/64a884100190695
_________________
<Clever text here>
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Oct 01, 2010 7:25 pm   
 
One small change should fix most of your problem:
Code:
<alias name="EmptySellQueue" id="69">
      <value>#if (@SellQueue) {
#SEND {%pop(SellQueue) }
//#t- CheckSellQueue
}</value>
    </alias>
The main thing is eliminating the use of %countlist, that function does about 20 times the work you need done.

I am also going to guess that %countlist could use some attention from Zugg. It does sound like it is taking far too long to complete for such a small list.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Oct 01, 2010 7:59 pm   
 
%countlist is as efficient as it's going to be. It loops through the list, does a lookup of each string in the result table and increments the count in the result table. Nothing else it can do faster. I think the problem is elsewhere as my tests with %countlist were all very fast.

Nothing should cause any freeze of 1.5 minutes. All I can suggest is running the Script Debugger window and turning on the Show All Scripts message and see what trigger or script is taking all of the time. I could not reproduce the freeze with testing your script here, so it might be interacting with some other script in your session.
Reply with quote
complex
Apprentice


Joined: 12 Apr 2004
Posts: 134
Location: USA

PostPosted: Fri Oct 01, 2010 8:18 pm   
 
So what happens then if %pop(SellQueue) finds nothing in the list, will it loop indefinitely?
_________________
<Clever text here>
Reply with quote
complex
Apprentice


Joined: 12 Apr 2004
Posts: 134
Location: USA

PostPosted: Fri Oct 01, 2010 8:52 pm   
 
I got it, the trigger (%d)*({@WeaponList}) being called something like 14000 times, filling up the queue. I am not sure why since there was only ever one output from the mud between calls, but if I disable the matchtrigger before I try to empty the queue everything works like expected.
_________________
<Clever text here>
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Oct 01, 2010 9:23 pm   
 
Or you can try turning off the "Trigger on Trigger" option for the trigger to prevent it from firing again while it is already running. My guess is that it was triggering again on the command you were sending to the MUD with #send (which echos the command, and fires triggers on the command).
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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