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
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Sep 02, 2010 3:39 am   

Suggestion: Change to %upper and %lower
 
Would it be possible to have %upper and %lower both have an optional parameter added which allows the user to specify a range of what they want made uppercase or lowercase?

Example:
%upper("chamenas", 1)
returns: Chamenas

%upper("chamenas", 2)
returns: cHamenas

%upper("chamenas", 1-3)
returns: CHAmenas

The same would work for %lower, except it would obviously lowercase instead.

The reason I am proposing this idea is because, while %proper exists, %proper indiscriminately lowercases all letters after the first. Sometimes, especially for names, I only want to uppercase the first letter, I don't always want to lowercase all of the letters afterwards. Here's an example of what I mean:

qui'Pichi

Now, of course, one would hope that if someone remembers to uppercase the P that they will properly uppercase the Q. But when you're making scripts that rely on user input, you can't always expect that they'll remember to do that. Using %proper on the above would return: Qui'pichi, when what I would want is: Qui'Pichi

It's just a small suggestion, and I can easily make a function for my needs if it's not taken. However, I figured it could be a problem others might run into, and this would save anyone in my situation (myself included) a bit of scripting.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Sep 02, 2010 1:58 pm   
 
That's not how those functions are supposed to work. Just use Lua.

Code:
local word = zs.param(1)
local firstIndex = zs.param(2)
local secondIndex = zs.param(3)
local newWord = word:gsub(string.sub(word, firstIndex, secondIndex ), string.upper)
print(newWord)


Put that in an alias or function.

For example:
Code:
#call ChangeCase("chamenas",2,3)

outputs

cHAmenas

The Lua function would be:

function ChangeCase(word,firstIndex,secondIndex)
  local newWord = word:gsub(string.sub(word, firstIndex, secondIndex ), string.upper)
  return newWord
end


I cannot for the life of me figure out how to get Cmud to return something from a function using Lua so you could just do $var = @ChangeCase("chamenas",2,3) for example. I know how to do it with an Lua function but you have to preload those. I tried zs.cmd.return but that doesn't work either.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Sep 02, 2010 3:01 pm   
 
I could make a CMUD function to do it, I just figured it would be something interesting to add. I'm aware it's not how they currently work, but it was a suggestion for something they could be changed to, but I'm also well aware that they might not be changed. I'll probably just make my function either way, so I can keep working on my script.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Sep 02, 2010 4:50 pm   
 
Also, see the %proper function if you just want to uppercase the first letter (which is the most common need).
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Sep 02, 2010 5:26 pm   
 
Well, as mentioned, the problem is that %proper lowercases everything else. I'm thinking of circumstances in which the first letter needs to be capitalized, but other letters need to be untouched. However, since those cases would be rare, I tried to think of a more general use that people might use to cover all sorts of rare circumstances.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Sep 02, 2010 7:11 pm   
 
How exactly would you do it in a zscript function? Zscript doesn't have a substring function, although I wish it did.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Sep 02, 2010 8:43 pm   
 
Quote:
Zscript doesn't have a substring function

Yes it does, it is called %copy
Reply with quote
Martaigne
Wanderer


Joined: 05 Jan 2002
Posts: 88
Location: Atlanta, GA

PostPosted: Thu Sep 02, 2010 10:13 pm   
 
This is relatively easy. :) Just make sure that you enclose the first string in quotes if it's anything more than a single word.

Code:
<func name="casechange" id="458">
  <value>//Usage: @casechange(s, c, r[, l]) where
//  s is the string you wish to change case on,
//  c is a string of value 'upper' or 'lower',
//  r is the start of the letter range to change,
//  l is the length of the letter range to change.
//  If l is not specified, the length defaults to 1.
//  Ex: @casechange("teststring", upper, 4, 6)
//  Results in: tesTSTRINg
//  Ex: @casechange("teststring", upper, 4)
//  Results in: tesTstring
$newstring = ""
$string1 = ""
$string2 = ""
$string3 = ""
#IF (%param(4)) {
  $string1 = %copy(%param(1), 1, (%param(3)-1))
  $string2 = %copy(%param(1), %param(3), %param(4))
  $string3 = %copy(%param(1), (%param(3)+%param(4)), %len(%param(1)))
  } {
  $string1 = %copy(%param(1), 1, (%param(3)-1))
  $string2 = %copy(%param(1), %param(3), 1)
  $string3 = %copy(%param(1), (%param(3)+1), %len(%param(1)))
  }
#IF (%param(2) = "upper") {$string2 = %upper($string2)}
#IF (%param(2) = "lower") {$string2 = %lower($string2)}
$newstring = %concat($string1, $string2, $string3)
#RETURN $newstring</value>
  <arglist>$string,$case,$rangestart,$rangeend</arglist>
</func>
_________________
Unwritten Legends
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Fri Sep 03, 2010 12:16 am   
 
Yes, yes. I was just suggesting something that could be imped for all CMUD users in general, I'm aware that this can be made into a function as well. Thank you though. Smile

Edit:

btw, for the curious, whenever I have // for comments at the beginning of the line, the CMUD parser doesn't see them as comments and tries to send it as text to the MUD :(
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Fri Sep 03, 2010 12:26 am   
 
Just use the other one. \\
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Fri Sep 03, 2010 12:39 am   
 
Same problem with those ones, Arminas. :-/
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Sep 03, 2010 5:00 pm   
 
// work fine for me here. Here is an example:
Code:
<alias name="test" id="1">
  <value>// comment
// test</value>
</alias>

Running the "test" alias doesn't cause anything to be sent to the MUD.

With the // comments, you MUST follow the // with a space character for them to work properly. So maybe that's your problem?
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Fri Sep 03, 2010 5:48 pm   
 
How the heck am I missing all this stuff... Confused Why is it called %copy? Laughing Well that's good to know!
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Fri Sep 03, 2010 6:03 pm   
 
@oldguy2 - Senile Twisted Evil , last one I promise Rolling Eyes
_________________
Taz :)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Sep 03, 2010 6:18 pm   
 
Quote:

With the // comments, you MUST follow the // with a space character for them to work properly. So maybe that's your problem?


It's not. I use //comment exclusively and CMud has not once thrown a fit about it. If it's supposed to be, whatever code you have for it is apparently not working at any point on my end.
_________________
EDIT: I didn't like my old signature
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Fri Sep 03, 2010 7:10 pm   
 
Code:

<alias name="test" id="536">
  <value>// This is a test alias
// In this alias I am appropriately using comments
// However, the comments do not work.
#show Test</value>
</alias>


Here's an example. This sends the lines:
This is a test alias
In this alias I am appropriately using comments
However , the comments do not work.

to the MUD just like it would if I had put #send in front of them, then properly displays:

Test


Comments after a line of script, such as:

#show "Hey there" // this is a comment

works, however, no other kinds of comments work for me, and haven't in any version.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Sep 03, 2010 7:18 pm   
 
It works fine for me. Have you tried it in a blank session? Have you modified any of your special character variables?
_________________
Asati di tempari!
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Fri Sep 03, 2010 8:01 pm   
 
Focus char is set to: /
Class char is set to: \

To my knowledge I havent ever modified them, I did change movement char to :

I'll try iti n a Blank Session
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Fri Sep 03, 2010 9:08 pm   
 
Defaults

Focus Char: :
Class Char: /
Movement Char: .

Something else you may need to check is that if the comments are in an alias that it isn't the "Auto append" setting being ticked causing the issue. It could be a combination of that setting and a change in the special characters.

[EDIT] In a blank session all it takes to reproduce this is disable the class char and change the focus char to / and create an alias with a comment and run it. [/EDIT]
_________________
Taz :)
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Fri Sep 03, 2010 9:24 pm   
 
Yup, changing / back to the Class character did it. I suppose it might be intentional then, though it seems silly to be unable to use comments appropriately if you change the special characters.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Sep 04, 2010 2:45 am   
 
Taz wrote:
@oldguy2 - Senile Twisted Evil , last one I promise Rolling Eyes


I know. It is troubling. Sigh.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Sat Sep 04, 2010 1:27 pm   
 
oldguy2 wrote:
Taz wrote:
@oldguy2 - Senile Twisted Evil , last one I promise Rolling Eyes

I know. It is troubling. Sigh.

Small comfort I know but you're not the only one. I've not quite reached forty but I'm far too aware my brain just isn't as capable as it once was. Crying or Very sad
_________________
Taz :)
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