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


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Apr 15, 2007 9:02 pm   

[1.27] One thing that irritates me...
 
This was actually an issue in previous versions as well, although it may not be a bug, but I'll admit, it really does irritate me.

This is just a sample (although it's based off an actual alias.

Code:
%if (%0, %0, %db(@Gamedb, GameChan)) Thanks for playing! See you next time!


Say I have the value for GameChan to be group. In zMUD, the alias with no argument returns:

Code:
group Thanks for playing! See you next time!


Now if I put that code in CMUD, it concatenates the channel and the first word, thus returning:

Code:
groupThanks for playing! See you next time!


As you might guess, that doesn't bode well with the MUD, and it thinks I've entered an incorrect command. Now, I've found a fix for it, but that fix really isn't something I want to go through and seek for the 40+ different variances of it throughout all the scripts. The fix is:

Code:
%if (%0, %0, %db(@Gamedb, GameChan)) " "Thanks for playing! See you next time!


The " " forces a space between the variable and the first word. Now my question is - can we do away with that? If I absolutely have to, I'll go through and change all my scripts. But if this can be fixed in a near-future version, I know at least one person will appreciate it. :) Or maybe someone has an even better fix. Thanks in advance.

Charneus
Reply with quote
shalimar
GURU


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

PostPosted: Sun Apr 15, 2007 11:08 pm   
 
This issue has been bothering me as well.. it seems that ANY % function will eat any whitespace immediately after the closing parenthesis
_________________
Discord server
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Apr 17, 2007 6:22 pm   
 
You cannot have a space between the function name and the (. If you use:
Code:
%if(%0, %0, %db(@Gamedb, GameChan)) Thanks for playing! See you next time!

then it will work properly.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Tue Apr 17, 2007 7:15 pm   
 
Ok. I can get rid of that, however, reformat puts the space right back in place again. Perhaps it's something to do with the zMUD code? Like I said, it worked in zMUD, but not in CMUD at all.

Charneus
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Apr 17, 2007 7:20 pm   
 
Hmm, reformat is supposed to be putting the space *after* the ( and not before it, so that sounds like a bug in the reformatter.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Tue Apr 17, 2007 7:28 pm   
 
Oh wait. I misread what you had put up there. Yeah, there has never been a space between %db and (. It's always been %db( @blah.

Either way, tried it without the spaces, and it didn't work. All it returned was "Thanks for playing! See you next time!" without the channel name in front of it, thereby not producing the output I needed. :P

Charneus

Also, again, the only fix I've seen is putting " " after the channel, but before the channel output.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Tue Apr 17, 2007 8:03 pm   
 
Another update regarding this...

Apparently, it won't even read the %db( @Gamedb, Gamechan)... it returns a blank (even if I have it populated). However, if I change that to read @Gamedb.Gamechan, it returns as expected. I'm going to edit some of the scripts and see if I can provide a better example of what's going on.

Charneus
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Apr 17, 2007 9:51 pm   
 
OK, first I don't see Reformat adding the space before the (. It always seems to add the space *after* the ( when I try it. And that is correct.

I'd need to see your full alias to help more with this. I created an alias called "test" with the following value:
Code:
%if(%0, %0, %db(@Gamedb, GameChan)) Thanks for playing! See you next time!

and when I typed "test hello" it properly displayed:
Code:
hello Thanks for playing! See you next time!

Part of the problem with your script may be that you are not really telling CMUD what is a string and what is not. After all, if you want CMUD to treat "Thanks for playing" as a string, then should it include the space before it or not? Consider the function:

%concat( a, b, c)

What should the result of this be? Should it be "abc" as expected from most languages, or should it be "a b c" because of the extra spaces? When you don't specify the double-quotes then CMUD has to guess what you are trying to do. CMUD tries to work like a "normal" language and returns "abc" in this case, stripping the leading spaces. That is why CMUD is stripping the leading space before "Thanks". It sees that as a space delimiter between arguments and not as a literal " " string.

The fully correct version of your script should probably be something like this:
Code:
%if(%0, %0, %db(@Gamedb, GameChan)) " Thanks for playing! See you next time!"

That will ensure that you always get the space that you want and that CMUD doesn't have to try and guess.

So don't just put " " in front of "Thanks". Put the " quotes around the entire string to be more correct, just like you would in any other programming language.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Apr 18, 2007 6:43 pm   Revisited...
 
After trying what you discussed, Zugg, I find that the root of my problem (aside from the string itself) is that the %db(@GameDB, Gamechan) is not being captured at all. I set up a new test to see if I could isolate the problem, and this is what was returned.

I first started with a testdb.
Code:
#addkey testdb chan echo


Then I created an alias (which, for some reason, wouldn't let me do it from the command line, returned "Alias not defined" error) that consisted of the following code:
Code:
Alias: test
Command: %if(%0, %0, %db(@testdb, chan)) " Hello world!"


Now, if I type 'test' with an argument, it works correctly.

test say returns say Hello world!

However, if I don't use an argument, it just returns the " Hello world!" portion of the script.

I then modified the alias a little. I changed the command to
Code:
#if (%0) {%0 " Hello world!"} {#exec %db(@testdb, chan) " Hello world!"}


That fixed the problem. After determining that #exec worked, I went back to the original code and tried placing both #exec and %exec in front of the %db to see if I could get it to work. Using #exec just returned:
Code:
#exec Hello world!

while %exec returned:
Code:
 Hello world!


It appears that it's not expanding the database variable if used by itself like it was in zMUD. This causes a problem because in the original script, there are several places where %if(%db(@testdb, test)>5, %db(@testdb, chan), %db(testdb, chan2)) " Hello World!", and if it's not expanding the %db variable, then it's not going to fire correctly.

I hope this helps clarify some of the situation, and maybe there is a fix for it other than having to reprogram something in CMUD. Thanks, Zugg. :)

Charneus
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Apr 19, 2007 5:05 pm   
 
I think there might be several problems here.

1) You shouldn't be using %0. That is why it doesn't work from the command line. The correct way to access all arguments in CMUD is using the %params function. Yes, I know it makes the script a bit longer, but it also makes it much easier to read and debug/support later.

2) Your other problem is that when you just have an alias like this
Code:
Alias: test
Command: %if(%0, %0, %db(@testdb, chan)) " Hello world!"

you are calling %if and returning a result, but you are not telling CMUD what to do with it. Same thing with calling #EXEC with the %db function. What #EXEC is trying to do is execute your %db result as a command (or alias). If you want to send stuff to the MUD, then you should be using the #SEND command, like this:
Code:
Alias: test
Command: #SEND %if(%params, %params, %db(@testdb, chan)) " Hello world!"

In general, putting a function (or variable) at the beginning of the line is undefined. You need to use #SEND to send it to the MUD, or #EXEC to execute it as a command or alias.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Apr 19, 2007 8:20 pm   
 
Aha! That seems to have fixed all problems (thus far). I forgot about the %0 part. Now on to rewriting the scripts (love notepad's replace function).

Thanks Zugg.

Charneus
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