|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sat Dec 15, 2007 5:04 pm
Simutronics GSL |
After upgrading to the newest version from 1.something I noticed that the %gsl function for at least letters "l" and "m" returns a string with much whitespace between words. For example if %gsl(l) was expected to return "An old key" you might get "An <much whitespace here> old <much whitespace here> key" which I find a bit annoying. I just had to write my own innerTrim function to "normalize" the sentence. I hope this will be fixed at some point although I realize that while annoying it's not blowing up CMUD as certain other bugs (like writing """ in a string list variable for instance).
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Dec 15, 2007 6:08 pm |
This isn't really a bug in CMud so much as CMud not taking the initiative. The extra whitespace shown is coming straight from Simutronics servers as part of the GS tag. I think they're doing a fixed-length formatting function on their end.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sun Dec 16, 2007 11:50 am |
I believe you are wrong there because it worked nicely before the update to 2.18. I was as mentioned before coming from the latest 1.something.
Zugg could have removed trimming deliberately but why would he? |
|
|
|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sun Dec 16, 2007 12:01 pm |
A little correction to myself:
I didn't use the %gsl function before as the trigger was able to give me a nicely formatted string in %2 instead. After updating this didn't work anymore so I had to look to the %gsl function to get the information. Why I can't use %2 (or many other parameters that I tried too) I do not know but I cannot find any reason for it except that it's a bug. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Dec 17, 2007 6:20 pm |
I think you'llhave to explain a little further about how you were using %2, and how it wasn't working. Can you give us the code you were using and what happened?
|
|
|
|
EfrenCecht Newbie
Joined: 12 Dec 2007 Posts: 5
|
Posted: Mon Dec 17, 2007 10:11 pm |
I don't know if this will help much but this is the code i'm using to remove those spaces which actually arn't considered spaces by CMUD but rather as words.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<class name="Hands">
<trigger type="GSL" priority="1930">
<pattern>m</pattern>
<value>mainhand = ""
mainhandtemp = %gsl(m)
mainhandwords = %numwords(@mainhandtemp," ")
#WHILE (@mainhandwords > 0)
{
#IF (%word(@mainhandtemp,@mainhandwords," ") != "")
{
mainhand = %word(@mainhandtemp,@mainhandwords," ") + " " + @mainhand;
}
mainhandwords = @mainhandwords - 1;
}</value>
</trigger>
<trigger type="GSL" priority="1940">
<pattern>l</pattern>
<value>lefthand = ""
lefthandtemp = %gsl(l)
lefthandwords = %numwords(@lefthandtemp," ")
#WHILE (@lefthandwords > 0)
{
#IF (%word(@lefthandtemp,@lefthandwords," ") != "")
{
lefthand = %word(@lefthandtemp,@lefthandwords," ") + " " + @lefthand;
}
lefthandwords = @lefthandwords - 1;
}</value>
</trigger>
<button autosize="false" width="107" autopos="false" top="720" transparent="false" color="black" textcolor="yellow" priority="1950">
<caption>@lefthand</caption>
</button>
<var name="lefthand">Empty </var>
<button autosize="false" width="107" autopos="false" top="700" transparent="false" color="black" textcolor="yellow" priority="1970">
<caption>@mainhand</caption>
</button>
<var name="mainhand">Empty </var>
<var name="mainhandwords">0</var>
<var name="lefthandwords">0</var>
<var name="lefthandtemp">Empty</var>
<var name="mainhandtemp">Empty</var>
</class>
</cmud>
|
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Dec 17, 2007 10:23 pm |
No, they are not words. By default, %numwords() uses the space as a boundary. A string with 14 spaces would be considered to have 14 words, but all the words happen to be a null length.
You should be able to pick up on this by carefully examining the output using the %word() function (%word works the same way as %numwords, except it allows you to specify a specific one instead of counting them up). Instead of returning a space, the 14th "word" should be literally nothing at all. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
EfrenCecht Newbie
Joined: 12 Dec 2007 Posts: 5
|
Posted: Mon Dec 17, 2007 10:32 pm |
Yeah that's exactly what i was getting out of it so I was quite confused. I guess I just assumed that %numwords() only counted words eather way though the code I posted takes out those spaces but if someone knows a better way I'd love to know how.
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Dec 17, 2007 10:42 pm |
A simple regex substitution takes care of it
Code: |
$var=%subregex($var,"\s{2,}"," ") |
This regex says to match on any place there are 2 or more spaces with a preference on the more.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
EfrenCecht Newbie
Joined: 12 Dec 2007 Posts: 5
|
Posted: Tue Dec 18, 2007 2:52 am |
see now that's just too easy, thank you very much that works like a charm
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Jan 07, 2008 9:37 pm |
I don't remember doing anything to change whether spaces in GSL are trimmed or not. But you definitely uncovered a bug in the %word command. It isn't supposed to treat multiple spaces as multiple works like that. I think it's related to how the new string list hash table works (%word uses the string list hash table code replacing " " with "|"). Anyway, I've added this to the bug list so that CMUD will treat multiple spaces as a single space like it did in previous versions.
|
|
|
|
|
|