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
harley
Apprentice


Joined: 05 Apr 2008
Posts: 121

PostPosted: Sat May 31, 2008 5:52 pm   

[2.25] Upgrading Killed Functions
 
A friend wrote this.. As i'm not the greatest with all features..
but this function among many others stopped working with 2.25
Code:

#return %ansi(%eval(%if($Color > 8, $Color - 8, $Color + 8)))%subregex(%subregex(%subregex(" "$Input" ", "((?-i)[a-z]*)((?-i)[A-Z0-9])((?-i)[a-zA-Z0-9]*)((?-i)[^a-zA-Z0-9])|((?-i)[a-z])((?-i)[a-z]+)((?-i)[^a-zA-Z0-9])| (?-i)([a-z]) ", "%if(%len(%pat(2)), %concat(%pat(1), %ansi("$Color"), %pat(2), %ansi("%eval(%if($Color > 8, $Color - 8, $Color + 8))"), %pat(3), %pat(4)))%if(%len(%pat(6)), %concat(%ansi("$Color"), %pat(5), %ansi("%eval(%if($Color > 8, $Color - 8, $Color + 8))"), %pat(6), %pat(7), %pat(8)))"), " (?-i)([a-z]) ", " %ansi("$Color")%pat(1) "), "^ | $", "")
All it really does is adds color codes to a string. But since its not working i get messages like
Code:
[Spellup]:  ()

when it used to look like
Code:
[Spellup]: Spell Wore Off (Underwater breathing)

granted, it was colored on client :)
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Sat May 31, 2008 8:40 pm   
 
Well, here is a quick fix, assuming that when this code was written there were no functions (which is doubtful since #RETURN exists solely for the sake of functions):
Code:

#FUNCTION somename() {#return %ansi(%eval(%if($Color > 8, $Color - 8, $Color + 8)))%subregex(%subregex(%subregex(" "$Input" ", "((?-i)[a-z]*)((?-i)[A-Z0-9])((?-i)[a-zA-Z0-9]*)((?-i)[^a-zA-Z0-9])|((?-i)[a-z])((?-i)[a-z]+)((?-i)[^a-zA-Z0-9])| (?-i)([a-z]) ", "%if(%len(%pat(2)), %concat(%pat(1), %ansi("$Color"), %pat(2), %ansi("%eval(%if($Color > 8, $Color - 8, $Color + 8))"), %pat(3), %pat(4)))%if(%len(%pat(6)), %concat(%ansi("$Color"), %pat(5), %ansi("%eval(%if($Color > 8, $Color - 8, $Color + 8))"), %pat(6), %pat(7), %pat(8)))"), " (?-i)([a-z]) ", " %ansi("$Color")%pat(1) "), "^ | $", "")}

One big problem is that you have undefined local variables in the script so I am assuming that this is not the entire script but a snippet. You also have to give the function a name. Bottom line is that #RETURN is used to exit a #FUNCTION and cannot exist outside that context. So by giving you this code snippet I am hoping you get the idea of how to fix the script. Read this, this and this for further enlightenment. The basic idea is that you cannot use a command in lieu of a function (except for the #FUNCTION command, of course. Wink)
_________________
Sic itur ad astra.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Sat May 31, 2008 10:07 pm   
 
Don't use %pat with %subregex any more. That's the problem here. Use \1, \2, etc instead.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Sat May 31, 2008 10:28 pm   
 
Larkin, are you saying that #RETURN {} outside of a #FUNCTION is valid? If so, then there is a bug because when I try it, CMUD gets an access violation.
_________________
Sic itur ad astra.
Reply with quote
harley
Apprentice


Joined: 05 Apr 2008
Posts: 121

PostPosted: Sun Jun 01, 2008 12:13 am   
 
This is a function.
I just pasted the contents of the function..
The name of the function is AnsiHighlight
I'll be back i'm sure:)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Sun Jun 01, 2008 2:10 am   
 
Larkin is correct that the usage of %pat within the quoted substitution string of %subregex is the problem. I am sorry I still haven't really gotten to fixing the help on this.

The usage of nested subregex is bad, but not wrong. There are some other things that look really wrong with how it was written though; and if you provide some details about what exaclty it is supposed to do I will try to write it in a better fashion.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
harley
Apprentice


Joined: 05 Apr 2008
Posts: 121

PostPosted: Sun Jun 01, 2008 2:41 am   
 
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <func name="ansiHighlight">
    <value>#return %ansi(%eval(%if($Color > 8, $Color - 8, $Color + 8)))%subregex(%subregex(%subregex(" "$Input" ", "((?-i)[a-z]*)((?-i)[A-Z0-9])((?-i)[a-zA-Z0-9]*)((?-i)[^a-zA-Z0-9])|((?-i)[a-z])((?-i)[a-z]+)((?-i)[^a-zA-Z0-9])| (?-i)([a-z]) ", "%if(%len(%pat(2)), %concat(%pat(1), %ansi("$Color"), %pat(2), %ansi("%eval(%if($Color > 8, $Color - 8, $Color + 8))"), %pat(3), %pat(4)))%if(%len(%pat(6)), %concat(%ansi("$Color"), %pat(5), %ansi("%eval(%if($Color > 8, $Color - 8, $Color + 8))"), %pat(6), %pat(7), %pat(8)))"), " (?-i)([a-z]) ", " %ansi("$Color")%pat(1) "), "^ | $", "")</value>
    <arglist>Input, Color</arglist>
  </func>
</cmud>

thats the XML for it. as it works in 2.18
What it does is just colors the words..Its hard to show you color on here but.. lets try:P
[Spellup]: Spell Failed (Protection good)
the colors are not perfect.. no dark cyan, dull white/grey etc but you can see it.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <event event="onSpellCast" priority="3960">
    <value>#substitute {@ansiPrefix("Spellup")@ansiHighlight("Spell Cast On ", 11)@ansiHighlight(%if($Target, $Target, "Self"), 15)%ansi(12)" ("@ansiHighlight(@spellName($Spell), 15)%ansi(12)")"}
#addkey SpellupData Casting {0}
#if ((@spellIndex($Spell) == @spellIndex(@SpellupData.LastSpell)) AND ($Target == @SpellupData.Target))
{
  castnextspell
}</value>
    <arglist>Spell, Target</arglist>
  </event>
</cmud>

Thats one of the places (among many) that use it.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Sun Jun 01, 2008 12:40 pm   
 
I was a little bit confused about what some of the slop in that pattern was meant to do. It seems the substitution is aimed at always coloring the first character of a word a certain way. If this isn't exactly what you are looking for, then I would need many more examples of your usage to make it better.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <func name="ansiHighlight" copy="yes">
    <value>$Col1=%ansi($Color)
$Col2=%ansi(%bitxor($Color,8))
#RETURN %subregex($Input,"\b(\w)",%concat($Col1,"\1",$Col2))</value>
    <arglist>Input, Color</arglist>
  </func>
</cmud>
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
harley
Apprentice


Joined: 05 Apr 2008
Posts: 121

PostPosted: Sun Jun 01, 2008 6:16 pm   
 
Works like a charm!
Thanks so much.

edit, works great.. and so much smaller.. amazing:P
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Fri Jun 06, 2008 3:24 am   
 
So what's your game name and where did you get ahold of my script? :P Good to know the problem with it in advance so I can fix it for the rest of the clan, when I finally get time to re-install my cmud.
_________________
The Drake Forestseer
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Fri Jun 06, 2008 4:39 am   
 
Haha, btw, now I read further I see you tried to shrink it down, and yes, I originally used something similar to this too, But this one is designed for something slightly different.

It Highlights every leading capital, camel-case capital, or character following non-alphanumeric characters, egs:

@rmud@RC@rolor

@RC@rolor

@RT@rime: @R0@r0:@R5@r0

Treat @R as a bright character and @r as a dark i guess :P

Can't remember why i nested the regexps now, but I needed to in order to get the desired effect, i remember that clearly. If you can optimize it further, I certainly won't complain, just need to check all the different outputs that this actually provides first ;)
_________________
The Drake Forestseer
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Thu Jun 12, 2008 3:46 pm   
 
ok, with the conversion to \# syntax, the function is
Code:

#return %replace("_char(64)"%if(%lower($Color) == $Color, %upper($Color), %lower($Color))%subregex(%subregex(%subregex(" "$Input" ", "((?-i)[a-z]*)((?-i)[A-Z0-9])((?-i)[a-zA-Z0-9]*)((?-i)[^a-zA-Z0-9])|((?-i)[a-z])((?-i)[a-z]+)((?-i)[^a-zA-Z0-9])| (?-i)([a-z]) ", "%if(%len(\2), %concat(\1, _char(64)"$Color", \2, _char(64)"%if(%lower($Color) == $Color, %upper($Color), %lower($Color))", \3, \4))%if(%len(\6), %concat(_char(64)"$Color", \5, _char(64)"%if(%lower($Color) == $Color, %upper($Color), %lower($Color))", \6, \7, \8))"), " (?-i)([a-z]) ", " _char(64)"$Color"\1 "), "^ | $", ""), "_char(64)", "@")


(i can convert this to the ansi version later)

But now it's doing some stuff it never used to

First up, it's eating my spaces. But then there's the REALLY wierd part. If I include a number it adds some spaces in.
eg

gt @highlight("Bob Does Stuff 2000", R)
gt @r@RB@rob@RD@roes@RS@rtuff@R 2@r 000

Notice the random output in 2000
_________________
The Drake Forestseer
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