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
Toshiro
Beginner


Joined: 01 Nov 2006
Posts: 14

PostPosted: Thu Jan 04, 2007 11:21 pm   

Help with a Cmud script
 
Hey guys,
I recently wrote a script for my mud, but it was really rough since I don't understand programming very well, so I had someone fine tune it for me. He got all the kinks out and it ran very well in Zmud. Recently I've made the switch to Cmud, but he isn't here to back me up on this change, so I was wondering if you guys could help me out.

This is the original script.
Code:

#Trigger (bloody traces|tracks) of a (trolloc|human) leaving (%w)
#CO red
GetDir %3#SUB {%1 of %ansi( red, bold)a %2 %ansi(red)leaving %ansi( yellow)@dirchar%ansi( red, bold)%3%ansi( yellow)@dirchar}


#Trigger (tracks|bloody traces) of ~*(%w)~* leaving (%w).
#CO red
GetDir %3
#SUB {%1 of *%ansi( red, bold)%2* %ansi( red)leaving %ansi(yellow)@dirchar%ansi( red, bold)%3%ansi( yellow)@dirchar}


#Trigger (bloody traces) of (*) leaving (%w).
#CO red
GetDir %2
#SUB {bloody traces of %ansi( red, bold)%1 %ansi( red)leaving %ansi(yellow)@dirchar%ansi( red, bold)%2%ansi( yellow)@dirchar}



#Trigger (tracks) of (*) leaving (%w).
#CO green
GetDir %2
#SUB {tracks of %ansi( blue, bold)%1 %ansi( green)leaving %ansi(yellow)@dirchar%ansi( blue, bold)%2%ansi( yellow)@dirchar}


#Alias Getdir
#IF {%1="north"} {#VAR dirchar @northchar}
#IF {%1="east"} {#VAR dirchar @eastchar}
#IF {%1="south"} {#VAR dirchar @southchar}
#IF {%1="west"} {#VAR dirchar @westchar}
#IF {%1="up"} {#VAR dirchar @upchar}
#IF {%1="down"} {#VAR dirchar @downchar}

#Var dirchar {^^}
#Var westchar {<<}
#Var eastchar {>>}
#Var northchar {^^}
#Var southchar {vv}
#Var upchar {++}
#Var downchar {--}

So if
There are some tracks of a ridden mount leaving south.
was received from the mud, it would show

There are some tracks of a (ridden mount) leaving [vv](south)[vv]

the items in parenthesis are in blue, and the ones in brackets are in yellow. But it didn't work when I put it straight into Cmud, so I tried writing something new, but it doesn't work the same.

Here is what I have atm.


NEW CODE
Code:

#trigger There are some tracks of a (*) leaving (*).

#local $race
#local $direction
#local $dirchar
$race=%1
$direction=%2
#sw ($race="human") {#co red} ($race="trolloc") {#co red} ($race=”ridden mount”) {#co green} {#co green};
#sw ($direction="up") {$dirchar="++"} ($direction="down") {$dirchar="--"} ($direction="north") {$dirchar="^^"} ($direction="south") {$dirchar="vv"} ($direction="east") {$dirchar=">>"} ($direction="west") {$dirchar="<<"};
#sub {tracks of %ansi (blue,bold) $race %ansi (green) leaving %ansi(yellow)$dirchar%ansi( blue, bold)$direction%ansi( yellow)$dirchar}

#trigger There are some bloody traces of a (*) leaving (*).

#local $race
#local $direction
#local $dirchar
$race=%1
$direction=%2
#sw ($race="human") {#co red} ($race="trolloc") {#co red} {#co green};
#sw ($direction="up") {$dirchar="++"} ($direction="down") {$dirchar="--"} ($direction="north") {$dirchar="^^"} ($direction="south") {$dirchar="vv"} ($direction="east") {$dirchar=">>"} ($direction="west") {$dirchar="<<"};
#sub {tracks of %ansi (blue,bold) $race %ansi (green) leaving %ansi(yellow)$dirchar%ansi( blue, bold)$direction%ansi( yellow)$dirchar}



It compiles fine, but it won’t actually do anything, and I’m not sure why. Any help would be appreciated.

edited to format the first script.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Jan 05, 2007 12:32 am   
 
I take it that this is a representation of what's in the settings editor and you're not running this from the command line, right?

First, let me ask you what the output is. I assume it's something like this:

There are some tracks of a ridden mount leaving south.
There are some bloody traces of a trolloc leaving east.

I'm going to assume in my example that the line always begins "There are some something something of a" rather than "There are some something something of" - please correct me if I'm wrong.

And what you then want the trigger to do is simply highlight with different options - the whole line red if it's a trolloc or a human, green if it's not, with whatever it was that did the leaving in brighter red (or blue if the line is green) and the arrows in yellow. If that's the case, try this:

Trigger:
Pattern: There are some ($mode:{tracks|bloody traces}) of a ($leaver:*) leaving ($dir:%w).
Script:
Code:
#local $IsRed $DirArrows
//You can define all your localvars all at once like that.
#if ($leaver = "trolloc" OR $leaver = "human") {$IsRed=1} {$IsRed=0}
//Decide if the leaver is a red-line kind or a green-line kind.
#switch ($dir)
  (north) {$DirArrows="^^"}
  (east) {$DirArrows=">>"}
  (south) {$DirArrows="vv"}
  (west) {$DirArrows="<<"}
  (up) {$DirArrows="++"}
  (down) {$DirArrows="--"}
//Work out which arrows to use
#if ($IsRed) {#co red} {#co green}
//Do the colouring
#sub {There are some $mode of a %ansi(%if($IsRed,red,blue),bold)$leaver %ansi(red)leaving %ansi(yellow)$DirArrows%ansi(%if($IsRed,red,blue),bold)$dir%ansi(yellow)$DirArrows}
//Presto


EDIT: I notice that in your example, there are spaces between some things there shouldn't be (between the %ansi and the bracket that opens after it, for example) which will stop the script from working. Also note that if you add spaces before and after the function in the #sub command, you end up with two spaces together, which doesn't look great in the final output.
Reply with quote
Toshiro
Beginner


Joined: 01 Nov 2006
Posts: 14

PostPosted: Fri Jan 05, 2007 2:05 am   
 
Hey, thanks alot, I really appreciate the help. I didn't know you could use #if to add both scripts into one. I think I understand how it works, and I think I can replicate it on other scripts. One question I have though.


Pattern: There are some ($mode:{tracks|bloody traces}) of a ($leaver:*) leaving ($dir:%w).

You didn't make a local: $mode or $dir, so i'm assuming that when the trigger fires, it automatically creates a $mode? and also, would #switch ($dir) create a local: $dir whenever the trigger fires and it registers a direction?


PS. Sorry I left so many things to be assumed in my post. You were correct on all behalfs and your script runs very nicely. :)


EDIT: I was originally running the script by creating a package, and then creating the triggers inside the package. I tried doing this with your script, and it would not run, which is one reason that I think my other script wouldn't run either (among other possible reasons). I then created it as a normal trigger (not in any packages) and it ran correctly. I'm not really sure why it would matter, but it seems like it did. I have also had problems with a few packages that I have installed (I.E. they stop working correctly after a bit). Has anyone else noticed this?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Jan 05, 2007 2:35 am   
 
Yep, the trigger creates them for you. $localvar=value creates them implicitly too, but not inside #if statements. The #switch doesn't create it, it compares the value with the other expressions. See the help file on #switch, the alternate syntax is in one of the comments.

In answer to your edit, a normal user shouldn't need to do a thing with packages, just create the triggers and such under the session window - that is, when you open the package editor you'll see a tree view with a window in it with the same name as your session. That's the session window. If they're in a package outside the one containing the session window, you'll need to make sure the module that they're in is set to global and that they're not referring to any settings in other packages that aren't also global.
Reply with quote
Toshiro
Beginner


Joined: 01 Nov 2006
Posts: 14

PostPosted: Fri Jan 05, 2007 3:04 am   
 
Ah, I was referring to where you used %ansi(%if($IsRed,red,blue),bold) which was neat. I would have used two triggers when I wanted different colors like that. Also, I thought I read in the file that they removed the (Item1|Item2) option.

Code:

zMUD:
#IF ((@a > 1) | (@b = 2)) {true} {false}

CMUD:
#IF ((@a > 1) || (@b = 2)) {true} {false}


This was in the help file, but you used the first example in your post. Is this because you used it as part of a trigger as opposed to an #IF? Or could you have also used || in the Pattern: part of your trigger. Also, thanks for pointing out the alternate syntax for #SWITCH. It is alot easier to manage, edit, and it is nicer to look at :)
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Jan 05, 2007 3:13 am   
 
It's because it's trigger pattern syntax, yes. That's still the same as it was in zMUD, apart from the ($localvar:wildcard) bit.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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