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
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sat Apr 10, 2010 5:38 pm   

Script crashes CMUD
 
Here's the script:

Code:

<class name="Affects Window" id="554">
  <trigger name="Capture-Spells" priority="7090" regex="true" id="555">
    <pattern>^Spell:\s([\w '-]+)\s+:\smodifies [\w '-]+ by (?:-)?\d+ for (\d+) cycles</pattern>
    <value>_spell=%trim( %1)
$_time=%2+1
#IF (%ismember( @_spell, @_accept_spell)) {
  $_mem_num=%ismember( @_spell, @_accept_spell)
  _spell = %item( @_accept_spell, $_mem_num)
  #IF (%iskey( @_spell_list, @_spell)) {
    #VAR _spell_list.@_spell $_time
    #EXEC {show_aff}
    } {
    #ADDKEY _spell_list {@_spell=$_time}
    #EXEC {show_aff}
    $_str_len=@strlen( @_spell)
    _max_len=%max( @_max_len, $_str_len)
    }
  }
_spell=%null</value>
  </trigger>
  <alias name="show_aff" id="559">
    <value>$_iter=0
#LOOP $_iter,15 {
  #WINDOW Affects " "
  #ADD $_iter 1
  }
#LOOPDB @_spell_list {
  $_str_len=@strlen( %key)
  $_rem=@_max_len - $_str_len
  $_iter=0
  $_spell_name=%key
  #WHILE ($_iter!=$_rem) {
    $_spell_name=$_spell_name+" "
    #ADD $_iter 1
    }
  $_spell_name=$_spell_name+" "
  $_str_time=%string( %val)
  $_str_len=@strlen( $_str_time)
  $_rem=@_num_len-$_str_len
  $_iter=0
  $_value=%val
  #WHILE ($_iter!=$_rem) {
    $_value=" "+$_value
    #ADD $_iter 1
    } 
  #IF (%val!=0) {#WINDOW Affects %if( %val<2, %ansi( 12), %ansi( 10))$_spell_name%ansi( 15)": "%if( %val<2, %ansi( 12), %ansi( 10))$_value%ansi( 15)" ticks remaining."%ansi( reset)} {#WINDOW Affects %ansi( 14)%key%ansi( 12)" is missing."%ansi( reset)}
  }</value>
  </alias>
  <var name="_spell" id="560">Stone Skin</var>
  <trigger name="spell_tick_timer" priority="7150" regex="true" id="561">
    <pattern>^Timer now at 41 secs.$</pattern>
    <value><![CDATA[#IF (%numkeys( @_spell_list)>0) {
  #LOOPDB @_spell_list {
    $_time=%val
    #IF ($_time!=0) {
      $_time=$_time-1
      $_str_time=%string( $_time)
      $_str_len=@strlen( $_str_time)
      _num_len=%max( @_num_len, $_str_len)
      }
    #IF ($_time=0) {#IF (!%ismember( %key, @_req_spell)) {
        #show %ansi( 15)">>> "%key" has fallen! <<<"%ansi( reset)
        #DELKEY _spell_list %key
        } {
        _spell=%key
        #VAR _spell_list.@_spell 0
        }} {
      #IF ($_time=1) {#show %ansi( 15)%key" has 1 tick remaining!"%ansi( reset)}
      _spell=%key
      #VAR _spell_list.@_spell $_time
      }
    }
  #EXEC {show_aff}
  }
  ]]></value>
  </trigger>
  <func name="strlen" id="562">
    <value>$_com_str=$_str
$_iter=1
#UNTIL ($_str=$_com_str) {$_str=%left($_com_str, $_iter)
#ADD $_iter 1}
#RETURN $_iter-1</value>
    <arglist>$_str</arglist>
  </func>
  <alias name="affects" id="565">
    <value>$_send_aff=0
#switch (%begins( %1, "add")) {#IF (%ismember(%-2, @_accept_spell)) {$_mem_num=%ismember(%-2, @_accept_spell)
$_spell=%item(@_accept_spell, $_mem_num)
#show "The spell, "$_spell", is already in the list."} {#ADDI _accept_spell %-2
#show %-2" added to the accepted spells list."}}
  (%begins( %1, "remove")) {#show "remove"}
  {
  #send "aff"
  $_send_aff=1
  }
 
#if (!$_send_aff) {#send %cr}</value>
  </alias>
</class>


Here are the variables, they're in a separate class for individual session packages, whereas the main script is in my DSL package. However, this problem occurred last night before I made that change, when all of them were in one package in one class.

Code:

<class name="Affects-char" id="278">
  <var name="_num_len" id="279">2</var>
  <var name="_accept_spell" type="StringList" id="280">Sanctuary|Shield|Haste|Bless|Frenzy|Armor|Stone Skin|Protection Evil</var>
  <var name="_max_len" id="281">10</var>
  <var name="_req_spell" type="StringList" id="282">Sanctuary|Armor|Shield|Haste|Stone Skin|Bless|Frenzy</var>
  <var name="_spell_list" type="Record" id="283">Sanctuary=1|Armor=17|Shield=52|Frenzy=10|Bless=50|Stone Skin=44</var>
</class>


The problem? I first noticed it when I added the affects alias and began making functionality for adding spells to the list. I tried adding a spell, Giant Strength. Everything seemed to go fine until I ran the in-game affects command (there shouldn't be any looping here as I use aff for that, not all of affects). It brought up the first line:

You are affected by the following spells:

but then the program froze, and I got no more lines from the MUD. I couldn't do anything, and I had to end the process in the Task manager. Today, I tried inputting the spells manually by opening up the _accept_spell and _req_spell variables, I put in "Enhanced Recovery" and "Holy Presence". Saved them both, hit aff to run the in-game affects command and boom, it froze again. I don't have the slightest clue why it's freezing, and it's difficult for me to find problems in scripts. Thus, my usual method of isolating problems by breaking up parts of the script and putting in "break points" via shows won't work because the entire program itself seizes up and crashes. This seems indicative of a loop or memory issue, but I can't see where any of my loops or variables would cause that.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Apr 11, 2010 4:50 pm   
 
Code:

    #ADDKEY _spell_list {@_spell=$_time}


This is the line that did it. It needed to be:
#ADDKEY _spell_list @_spell $_time

I figured it out, but I have no reason why it was causing the program to crash. The only thing I can postulate is that it was trying to add information that it thought was there but wasn't, and so it crashed. And that this formatting doesn't make that assumption?

EDIT:
Nevermind, it's crashing again. Trying to add Protection Evil and Enhanced Recovery both failed and caused the crash. I know it's most definitely that line, but I don't know why. SOmehow Giant Strength worked, but it only worked after I put it in the stringlist manually. I added it to _accept_spell and _req_spell and then manually added it to _spell_list and suddenly it started working.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Apr 11, 2010 9:37 pm   
 
I talked with the Resident scripting guru for our mud and he pointed out an error which I had missed. It confirmed my suspicions that it had to do with a loop or memory issue. Specifically, $_rem=@_max_num-$str_len was sometimes giving a negative value, if a new string ended up not being evaluated before it was fed into the loop (which happened because of placement). Luckily it's all fixed.
_________________
Listen to my Guitar - If you like it, listen to more
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