Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Ambelghan
Novice


Joined: 04 Apr 2010
Posts: 49

PostPosted: Sat Aug 14, 2010 5:48 am   

3.22a DragonRealms %numwords(%gsl(m)) returning a weird count.
 
In cMUD 2.37 without anything in my hands #ECHO %gsl(m) returns the word "Empty" it has a #ECHO %numwords(%gsl(m)) of 1 word. Makes sense. However, when I get an "apple short bow" in my right hand, it has a #ECHO %gsl(m) of "an apple [there are 5 spaces here] short [there are six spaces here] bow" and a %numwords(%gsl(m)) of 12, despite the fact that there are only 4 words there. Though an issue, before it wasn't noticeable because I was only interested in the last word #ECHO %word(%gsl(m),%numwords(%gsl(m))) would return "bow"

In cMUD 3.22a without anything in my hands #ECHO %gsl(m) returns the word "Empty" it has a #ECHO %numwords(%gsl(m)) of 20 words, I'll assume there are some trailing spaces. Doesn't make sense, when I get an "apple short bow" in my right hand, it has a #ECHO %gsl(m) of "an apple [4 spaces here] short [7 spaces here] bow [5 spaces here]" and a %numwords(%gsl(m)) of 16, again only 4 real words here. This ends up being a major issue, as I am only interested in the last word, which is now a blank. #ECHO %word(%gsl(m),%numwords(%gsl(m))-4) seems to be "bow," I don't know what is going on, if someone could look at how %gsl(m) and %gsl(l) are being processed, it would be very helpful, thanks.
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Sat Aug 14, 2010 10:38 am   
 
This has been discussed somewhere before. The current implementation is that each space counts as a word delimiter. I'm of the opinion that only %numitems should act this way, but I believe this is way is more standard.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sun Aug 15, 2010 11:02 pm   
 
Numwords does have an option to count multiple spaces as a single space now.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="test" copy="yes">
    <value>$tvar="This   sentance  has five     words."
#show {%concat($tvar, " :numwords: ", %numwords($tvar," ",1))}
</value>
  </alias>
</cmud>


Note that I used " " to show the delimiter and that I used a 1 to say that I wanted to count multiple spaces as 1 space.

Output is:
Code:
This   sentance  has five     words. :numwords: 5


EDIT: The forum condensed the spaces for me now nice? I changed the color tags to code tags to show them.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram

Last edited by Arminas on Mon Aug 16, 2010 1:29 pm; edited 1 time in total
Reply with quote
Ambelghan
Novice


Joined: 04 Apr 2010
Posts: 49

PostPosted: Mon Aug 16, 2010 2:14 am   
 
I seem to be getting hit with a "working as intended" approach, however, unlike WOW I can alter things here, so I did this:
Code:
 hand=%replace($hand," ","|")
#FORALL (@hand)
{
  #IF (%i = "")
  {
    //#ECHO Nothing here
    hand = %delitem("",@hand)   
  } 
  //#ECHO %i
}
hand=%replace(@hand,"|"," ")
#RETURN (@hand)


A function with a parameter of $hand. This does remove all the extra spaces created in the %gsl(m) and %gsl(l), right and left hands respectively, and leave the last word of each variable as an actual word. So I can
Code:
 rthand = @GSLFixer(%gsl(m))
and get back "some dusky blue wooden crabs" with a %numwords(@rthand) of 5, and a last word of "crabs." Instead of
Code:
 rthand = %gsl(m)
and get back "some|dusky|blue|wooden|||||crabs||||" with a %numwords(@rthand) of 12, and a last word that is a blank.

This pretty much puts me back in business. Two things: 1) I wanted to use temp variables all the way through
Code:
$hand=%replace($hand," ","|")
#FORALL ($hand)
{
  #IF (%i = "")
  {
    //#ECHO Nothing here
    $hand = %delitem("",$hand)   
  } 
  //#ECHO %i
}
$hand=%replace($hand,"|"," ")
#RETURN ($hand)
However, that gave me rthand = "some dusky blue wooden" and a %numwords(@rthand) of 4, correct count, but I am not sure why it chopped off the word "crabs". 2)
Code:
hand=%replace($hand," ","|")
#DELITEM hand ""
hand=%replace(@hand,"|"," ")
#RETURN (@hand)
crashed CMUD
Code:
hand=%replace($hand," ","|")
#DELITEM hand " "
hand=%replace(@hand,"|"," ")
#RETURN (@hand)
Code:
hand=%replace($hand,"","|")
#FORALL (@hand)
{
  #IF (%i = "")
  {
    //#ECHO Nothing here
    hand = %delitem("",@hand)   
  } 
  //#ECHO %i
}
hand=%replace(@hand,"|","")
#RETURN (@hand)
and
Code:
hand=%replace($hand," ","|")
#FORALL (@hand)
{
  #IF (%i = " ")
  {
    //#ECHO Nothing here
    hand = %delitem(" ",@hand)   
  } 
  //#ECHO %i
}
hand=%replace(@hand,"|"," ")
#RETURN (@hand)
didn't work properly, not sure why on either, or why I can't use temp variables throughout. Apparently, earlier versions of CMUD just never put spaces after the last word, so it was never an issue, for me. However, it also, apparently, never correctly captured what was in each hand, leaving weird spacing. If someone can come up with a way to use only temp variables, that would be cool. I'll repost the code in another thread as a fix for others, if no one has a suggestion. Good day.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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