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


Joined: 12 Jun 2006
Posts: 106

PostPosted: Mon Jul 31, 2006 3:31 pm   

%right, %rightback
 
Noticed this while in zMUD and confirmed that it's also on CMUD.

%right and %rightback have the exact same help, saying they both return the right most N characters of the string.

%right does what %leftback does(except from the other side obviously!).

%rightback does what %left does.

>#SHOW %left("ABCDEFGH", 2)
AB

>#SHOW %leftback("ABCDEFGH", 2)
ABCDEF

>#SHOW %right("ABCDEFGH", 2)
CDEFGH

>#SHOW %rightback("ABCDEFGH", 2)
GH
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4411
Location: Pensacola, FL, USA

PostPosted: Mon Jul 31, 2006 10:02 pm   
 
Shouldnt right and rightback be swapped?

Since in the example above, %left only returns 2 charecters, so should %right, instead it shows the other 6.
_________________
Discord: Shalimar#3679
Reply with quote
edb6377
Magician


Joined: 29 Nov 2005
Posts: 482

PostPosted: Mon Jul 31, 2006 10:08 pm   
 
Yeah that would be my impression plus it makes more sense to me that way than the other way
_________________
Confucious say "Bugs in Programs need Hammer"
Reply with quote
saet
Apprentice


Joined: 12 Jun 2006
Posts: 106

PostPosted: Tue Aug 01, 2006 12:31 am   
 
I guess I forgot to mention that. My subject could have been a little more informative.

Btw, am I the first person to use %right and %rightback?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Aug 01, 2006 3:26 am   
 
Hardly. Rolling Eyes
_________________
EDIT: I didn't like my old signature
Reply with quote
edb6377
Magician


Joined: 29 Nov 2005
Posts: 482

PostPosted: Tue Aug 01, 2006 8:57 am   
 
Laughing Laughing Laughing Laughing Matt :)

I just learned to use them the way they were when i needed them. Didnt ever look at either of them close enough to really discern the situation. It should be changed. Usually when i looked it up i didnt have both going at once however and is most likely the reason I would have missed it.
_________________
Confucious say "Bugs in Programs need Hammer"
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Aug 01, 2006 9:47 pm   
 
Well, Zmud, CMud, and apparently even Zugg's style of programming doesn't have (a use for) a MID function, so any attempt to get at a mid-string portion of text will necessarily have to use at least two of the various %left/%right functions.

This was perhaps one of the most jarring differences in ZMud I had to get used to as an almost-exclusively BASIC coder.
_________________
EDIT: I didn't like my old signature
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Aug 01, 2006 10:09 pm   
 
Well, for people interested in the history of these functions, they came from the Lotus Notes scripting language. They had the left, leftback, right, and rightback functions as they are defined in zMUD. Back when zMUD was written, I was heavily into Notes programming, so several ideas came from there. Keep in mind that when zMUD was created, stuff like PHP didn't even exist! Yeah, it was a long time ago. But I'm afraid we are stuck with it. I can add *new* functions, but I'm not going to change how existing functions work because of zMUD compatibility issues.

I think the solution is to probably add a %mid or %substr function to CMUD. Then people won't need to mess with %left/%right.

At some point during the CMUD work, I'll probably go through my PHP manual and add more PHP-like functions anyway.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Aug 01, 2006 11:14 pm   
 
We already have %copy which is the Pascal name for the Basic 'mid' and C 'substr'. The benefits of the *back functions are that you don't need the extra use of the 'len' function. Processing wise it likely makes little difference, but the script looks a bit cleaner. I am sorry I didn't quite get the help totally clear on them, but they do function as intended. It is just a little confusing at times.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Rainchild
Wizard


Joined: 10 Oct 2000
Posts: 1551
Location: Australia

PostPosted: Wed Aug 02, 2006 6:59 am   
 
You could always (if it isn't already) make 'len' an optional parameter, if you do not specify a length, then it assumes 'everything after this' - means you can use %substr( ) as a left, right, or a mid.

eg
%substr( "abcdef", 1, 2 ) = "ab"
%substr( "abcdef", 3, 2 ) = "cd"
%substr( "abcdef", 5, 2 ) = "ef"
%substr( "abcdef", 1, 3 ) = "abc"
%substr( "abcdef", 4 ) = "def"

That should be powerful enough for any breaking apart that you need to do.

Currently %copy( "abcdef", 4 ) just returns a null string, so doesn't quite work as above, all the other examples work correctly.
Reply with quote
Kiasyn
Apprentice


Joined: 05 Dec 2004
Posts: 196
Location: New Zealand

PostPosted: Wed Aug 02, 2006 8:43 am   
 
a %numletters and %letter would be nice too =]
_________________
Kiasyn
Owner of Legends of Drazon
Coder on Dark Legacy
Check out Talon, an easy IMC connection.
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Aug 02, 2006 12:47 pm   
 
Kiasyn, could you be more specific about what you want the functions you mentioned to do?

Vijilante, yes, you are correct that %copy comes from the Pascal stuff. But Rainchild is correct that it should handle certain situations a bit cleaner.
Reply with quote
Rainchild
Wizard


Joined: 10 Oct 2000
Posts: 1551
Location: Australia

PostPosted: Wed Aug 02, 2006 11:24 pm   
 
To me, %numletters( ) sounds like the existing %len( ) function and %letter( ) sounds like return the character at a position, eg %letter( "abcdef", 3 ) = "c"

I wonder, is there a way to use something like

#VAR test "abcdef"
#SH @test[3]
>> "c"
#VAR test[3] "x"
#SH @test
>> "abxdef"

... I don't really have a current demand for that, but I might use it if it was there hehe.
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Aug 02, 2006 11:59 pm   
 
Rather than invent a new syntax, *if* I added something like this, the syntax would be more like other array/db references and would be something like this:
Code:
#VAR test "abcdef"
#SH @test.3
>> c
#VAR test.3 "x"
#SH @test
>> abxdef

This is the same syntax used for elements in a string list and for arrays, so it seems like it might make sense to work on a normal string. Not promising anything, just thinking out loud again.
Reply with quote
Kiasyn
Apprentice


Joined: 05 Dec 2004
Posts: 196
Location: New Zealand

PostPosted: Thu Aug 03, 2006 5:37 am   
 
Kiasyn wrote:
a %numletters and %letter would be nice too =]


blah = "whee test string"
#LOOP %numletters(@blah) {#if (%letter(@blah,%i) == 'e') {burp}}

etc :P
_________________
Kiasyn
Owner of Legends of Drazon
Coder on Dark Legacy
Check out Talon, an easy IMC connection.
Reply with quote
Rainchild
Wizard


Joined: 10 Oct 2000
Posts: 1551
Location: Australia

PostPosted: Thu Aug 03, 2006 6:26 am   
 
You could currently do this with:

#VAR blah "whee test string"
#LOOP %len(@blah) {#IF (%copy(@blah,%i,1)=="e") {burp}}

But admittedly you have to specify the final '1' as part of the %copy function, and %copy is a weird name for it ;)
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Aug 03, 2006 10:56 am   
 
You can already achieve that same sort of thing with %len and %copy. I don't see the need for new functions.
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