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
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Fri Sep 17, 2010 6:58 pm   

Advice on script
 
Okay I have finished my stutter script and have update it on the Library, but I want to get some advice from the gurus. Can you take a look at this and see if there is anything I can do to use new features of CMUD or speed it up.
Code:
#variable channel %1
#variable input %params( 2)
#variable person ""
#variable sentence ""
#variable emph ""
#variable loopcount 0
#variable s_word ""
#local $matched

;Check to see if the channel is a member of the sayto list
#if (%ismember( @channel, @sayto)) {

;Assign person variable and remove person from input variable
  #variable person %concat( %word( @input, 1), " ")
  #variable input %remove( @person, @input)
  }

;Check for a space a begining of input and remove
#variable input %trim( @input)

;Next check for an emphasis
#if (%begins( @input, "(")) {
  #call %match( @input, "(~(*~))(*)", emph, sentence)
 
;Remove space at begining of sentence to prepare to change into string list
  #variable sentence %trim( @sentence)
  } {#variable sentence @input}

;Change sentence into string list
#variable sentence %replace( @sentence, " ", "|")

;Now check the remaining input variable and make it stutter
 #forall @sentence {
  #add loopcount 1
  #print %i
  #if (%match( %i, %concat( "^({", @stutterlist, "})*"), $matched)) {
    #if (%random( 1, @st_relay)=1) {
;Need to change intensity of the stutter when it is a question or exclamation point at the end of the sentence
      #variable s_word %concat( $matched, "-", $matched, "-", %i)
      #variable sentence %replaceitem( @s_word, @loopcount, @sentence)
      }
    }
  }

;Replace pipe symbols with space to display remaining input
#variable sentence %expandlist( @sentence, " ")

;********* Display the finished output ***********************
#if ((@channel =~ "shout" || @channel =~ "yell") && (@emph))
{#print <color red>You can't use emphasis with shout</color>
  @channel @sentence}
 {@channel @person %quote( @emph) @sentence}


Also I want to change the script so if they sentence has a question mark of exclamation point then the stuttering get worse. See the comment in the script. The consonants are now hard-coded, but I want to make it a variable. IF you have an idea, please let me know.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Sep 17, 2010 8:44 pm   
 
One thing would be to change all the global variables that you set at the beginning (@channel, @input, @person, @sentence, @emph, @loopcount, @s_word) to local variables ($channel, $input, etc.). If you don't need to keep the values of these variables for other scripts, then local variables will be much faster, and you won't have to reset the variables to nulls at the beginning. Add the new local variables ($channel, etc.) to the #LOCAL declaration. Local variables are created afresh each time the script is run, are completely localized the the script while it is running, and disappear after the script completes. So, the first part would change from:
Code:
#variable channel %1
#variable input %params( 2)
#variable person ""
#variable sentence ""
#variable emph ""
#variable loopcount 0
#variable s_word ""
#local $matched

to
Code:

#local $matched $channel $input $person $sentence $emph $loopcount $s_word
$channel = %1
$input = %params(2)
$loopcount = 0

And similarly, later assignments of values to these local variables can be done with the syntax "$variablename = value".

If the @stutterlist does not change, you might want to make the value a default value. A global variable with a default value does not get re-saved to the package file, and thus is a touch faster.

The line
Code:
{@channel @person %quote( @emph) @sentence}

really ought to be:
Code:
{#send {@channel @person %quote( @emph) @sentence}}

It is bad practice to start a command line with a variable or function name. Instead, use the appropriate Cmud command (#CALL, #SEND, #EXEC, #SAY, or something else, depending on the command).

Otherwise, looks good.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sat Sep 18, 2010 10:42 pm   
 
Thanks for the advice. I tried to make them local, but was having problems doing it correctly. I wan't sure how locals worked with stringlists. Are the accessed with the @ sign still or just use the $ sign.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Sep 19, 2010 1:10 am   
 
Thanks Rahab. I changed them all over to local variables.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Sep 20, 2010 6:05 pm   
 
Yes, local variables which contain stringlists are still referred by the $ sign. $ indicates a local variable (of any type), and @ indicates a global variable (of any type). Almost anywhere you can use a global variable, you can use a local variable instead. The only trick with local variables is that you need to declare a local variable before you try to access a value within it. Setting a value to a local variable automatically declares it, but if the first time you refer to a local variable is trying to use or test the value, you must declare the variable in a #LOCAL command first.
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