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
Dervin
Newbie


Joined: 15 Sep 2011
Posts: 4

PostPosted: Mon Sep 19, 2011 9:34 am   

scripting help
 
I am new to cmud and I know nothing about programming or scripting. I am also not getting far by reading the help files in cmud. I have made some simple aliases but nothing to get excited about. I am hoping someone can help me (or write for me) a script for a power in the mud I play. Something I can use as an example while learning to write my own.
The guild power I need a script for is as follows: channel <power level> <type> <polarity> chaos into <target>.
There are 17 power levels {feeble, wimpy, light, modest, mediocre, moderate, decent, ample, strong, heavy, massive, incredible, spectacular, improbable, implausible, phenomenal, unearthly}, 8 types {mental, spiritual, physical, vital, sensory, hematic, adrenal, humorous} and 2 polarities {positive, negative}.

I want to write a script where I enter:
chn <number from 1 - 17> <first 2 letters of type> <p or n> <name of target>. (ie. chn 5 vi n thug) and have cmud send: channel mediocre vital negative chaos into thug.

It looks to me like I will need 27 different variables and I have no idea where to begin.

I will appreciate any help I can get with this.

Thanks.
Reply with quote
Fizgar
Magician


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

PostPosted: Mon Sep 19, 2011 3:45 pm   
 
There are a few different ways you could do this. This is the first that popped into my head this morning. Probably the easiest to explain/understand too.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="chn" copy="yes">
    <value>#local pl type pol

#switch (%1 = 1) {$pl = feeble}
  (%1 = 2) {$pl = wimpy}
  (%1 = 3) {$pl = light}
  (%1 = 4) {$pl = modest}
  (%1 = 5) {$pl = mediocre}
  (%1 = 6) {$pl = moderate}
  (%1 = 7) {$pl = decent}
  (%1 = 8) {$pl = ample}
  (%1 = 9) {$pl = strong}
  (%1 = 10) {$pl = heavy}
  (%1 = 11) {$pl = massive}
  (%1 = 12) {$pl = incredible}
  (%1 = 13) {$pl = spectacular}
  (%1 = 14) {$pl = improbable}
  (%1 = 15) {$pl = implausible}
  (%1 = 16) {$pl = phenomenal}
  (%1 = 17) {$pl = unearthly}

#switch (%2 = "me") {$type = mental}
  (%2 =~ "sp") {$type = spiritual}
  (%2 =~ "ph") {$type = physical}
  (%2 =~ "vi") {$type = vital}
  (%2 =~ "se") {$type = sensory}
  (%2 =~ "he") {$type = hermatic}
  (%2 =~ "ad") {$type = adrenal}
  (%2 =~ "hu") {$type = humorous}
 
#switch (%3 = "p") {$pol = positive}
  (%3 = "n") {$pol = negative}
 
#send %concat("channel ",$pl," ",$type," ",$pol," ",%-4)</value>
  </alias>
</cmud>


Here you have an alias named chn. It should work just how you want. If you typed chn 7 se n bear CMUD will send channel decent sensory negative bear to the mud. This is done by storing the power level, type and polarity of the spell into local variables using the #switch command. Then the string to be sent to the mud is built using those local variables, the fourth argument, and anything else passed to the alias. I'll try to explain more if needed later. Gotta be off to work now though. Have fun learning!
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Dervin
Newbie


Joined: 15 Sep 2011
Posts: 4

PostPosted: Tue Sep 20, 2011 7:04 am   
 
Thank you for your reply. I really appreciate it.

This script is interesting. I see how this should work, however, I can not make it do anything.
When I first ran it I was getting the following error: ERROR: Syntax error in Alias: chn : invalid local variable: pl
I looked at it a bit and found that if I changed the script type to xml (default is zscript), that error went away.
When I type one of my aliases in the command bar, the command is echo'd in the output window and the command takes effect on the mud.
When I type 'chn 7 me n rat', there is no output echo in the output window and no response from the mud, so my guess is that the script is not executing (based on the lack of an echo).

I copied it exactly as written to a text file, created a new alias 'chn', then imported the text from the file, set the script type to xml and that is as far as I have gotten towards making it work.
When I click on the editor tab and click'check syntax' I get: invalid local variable: pl at row 36 col 26. That line is #send %concat("channel ",$pl," ",$type," ",$pol," ",%-4)</value>
I changed the $ to @ for pl, type, and pol in that line and ran the 'check syntax' again. It returned: No errors. However the script still will not run.

If you can think of what I am doing wrong, please let me know.
I will spend some time tonight reading XML tutorials on the web. Hopefully I will learn something.

Thanks again
Reply with quote
Dervin
Newbie


Joined: 15 Sep 2011
Posts: 4

PostPosted: Tue Sep 20, 2011 7:42 am   
 
I got it working. I removed all of the XML tags, put the setting to zscript, added $ to each of the initial variable names and the script worked.

Thanks.
Reply with quote
Fizgar
Magician


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

PostPosted: Tue Sep 20, 2011 12:18 pm   
 
Sorry for the delayed response, I was busy all day long yesterday. I should have been more clear on how to use what I posted. That wasn't actually a full .xml export of a package but rather just the .xml copy of the alias it's self. To use all you needed to do was copy the stuff in the code box above to your clipboard, open the package editor in CMUD, then click on the window object/module you want the alias in and paste.
_________________
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: Tue Sep 20, 2011 3:37 pm   
 
This isn't a correction, but suggestions for anyone using code like this.

If you use #SWITCH on a single variable, you can simplify the syntax to:
Code:
#switch (%1)
  (1) {$pl = feeble}
  (2) {$pl = wimpy}
  (3) {$pl = light}
  (4) {$pl = modest}
  (5) {$pl = mediocre}
  (6) {$pl = moderate}
  (7) {$pl = decent}
  (8) {$pl = ample}
  (9) {$pl = strong}
  (10) {$pl = heavy}
  (11) {$pl = massive}
  (12) {$pl = incredible}
  (13) {$pl = spectacular}
  (14) {$pl = improbable}
  (15) {$pl = implausible}
  (16) {$pl = phenomenal}
  (17) {$pl = unearthly}

#switch (%2)
  ("me") {$type = mental}
  ("sp") {$type = spiritual}
  ("ph") {$type = physical}
  ("vi") {$type = vital}
  ("se") {$type = sensory}
  ("he") {$type = hermatic}
  ("ad") {$type = adrenal}
  ("hu") {$type = humorous}

#switch (%3)
  ("p") {$pol = positive}
  ("n") {$pol = negative}
 
#send %concat("channel ",$pl," ",$type," ",$pol," ",%-4)

Even better, when the variable in question is an integer range such as this, you could use #CASE:
Code:
#CASE (%1) {$pl = feeble}
  {$pl = wimpy}
  {$pl = light}
  {$pl = modest}
  {$pl = mediocre}
  {$pl = moderate}
  {$pl = decent}
  {$pl = ample}
  {$pl = strong}
  {$pl = heavy}
  {$pl = massive}
  {$pl = incredible}
  {$pl = spectacular}
  {$pl = improbable}
  {$pl = implausible}
  {$pl = phenomenal}
  {$pl = unearthly}


Since this part of the script in particular simply assigns the nth value to the variable $pl, it makes sense to just use the nth member of a list (remove the space after "ample" - that's there just for readability here in the forums):
Code:
powerlevels=feeble|wimpy|light|modest|mediocre|moderate|decent|ample |strong|heavy|massive|incredible|spectacular|improbable|implausible|phenomenal|unearthly
$pl=%item(@powerlevels,%1)
_________________
.geniusclown
Reply with quote
Dervin
Newbie


Joined: 15 Sep 2011
Posts: 4

PostPosted: Tue Sep 20, 2011 7:53 pm   
 
I certainly was not expecting such a quick response to my questions so no need to apologize for being busy. I appreciate the information, and now that I have a working script that I understand, I can start playing with the other #commands and see how they work.

I think it is great that you came back and showed different ways to do the same thing, giving me more options to explore and test.

Eventually I hope to be writing some nice scripts to improve the game play of the mud.

I am glad that the Cmud community has people willing to help beginners and answer questions.
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