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
Oozenthor
Beginner


Joined: 31 Jul 2006
Posts: 18

PostPosted: Thu Nov 16, 2006 9:57 am   

Expanding variables
 
An example of how I dealing with expanding variables at the moment:

given:
#VA TypicalVariable "a typical variable."

Case 1).
Display to issue window without sending to MUD:
#SAY This is how I deal with @TypicalVariable

Case 2).
Display to top window without sending to MUD:
#ECHO This is how I deal with @TypicalVariable

Case 3).
No display, but send to MUD:
#SEND %expand(This is how I deal with @TypicalVariable)

Case 4).
Display and send to MUD:
This is how I deal with @TypicalVariable


Now here are my thoughts on this:
case 3). I use this quite a lot to suppress output but it is quite awkward to use.
I have been looking for something like a #SENDX (expanded send or #SX) so the syntax is identical to case 1 & 2. Any ideas?

case 4). I know this is the "default" send to MUD command issue, but it looks horrid surrounded by code with every other command beginning with a hash character.
If there was a command like a #DSEND (expand, display and send or #DS), it would certainly make my scripts look a bit nicer.
Also it would give the option of some nice colour formatting for the local echo. ie: #DS %ansi(blue)look
I haven't figured out where the local echo gets sent to either (top or issuing window) or how to redirect it.

PS: How about a #REM command? I was using the ; character for comments but they got mangled too often by the compiler, so I stopped commenting my scripts, eeek.
I don't know if the #NOOP would suffice for this, the help file was a bit brief on the matter of it's usage.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Nov 16, 2006 12:41 pm   
 
Have you tried putting curly brackets around your text? That should treat it as a string but still expand your variable, and it should work the same for all the commands you're trying.
Reply with quote
Oozenthor
Beginner


Joined: 31 Jul 2006
Posts: 18

PostPosted: Thu Nov 16, 2006 2:26 pm   
 
- The curly braces work a treat thanks, have cleaned up my #SEND's nicely.
Also I found the bit about paramerter expansion in the "changes for zmud users/#VAR" section of the help which I guess holds true everywhere, not just in the #VAR command.
So I should only use the %expand() function when I need to control the expansion depth right?

- I guess I can fake local echo colours by:
#SA {%ansi(blue)This is how I deal with @TypicalVariable}
#SE {This is how I deal with @TypicalVariable}

Little bit messy, but at least functional.
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Fri Nov 17, 2006 3:56 am   
 
Quote:
case 4). I know this is the "default" send to MUD command issue, but it looks horrid surrounded by code with every other command beginning with a hash character.


#1 {This is how I deal with @TypicalVariable}
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Oozenthor
Beginner


Joined: 31 Jul 2006
Posts: 18

PostPosted: Fri Nov 17, 2006 4:37 am   
 
That works brilliantly!
Parameter expansion and colours, exactly what I was looking for.

Thanks everyone.
Reply with quote
Oozenthor
Beginner


Joined: 31 Jul 2006
Posts: 18

PostPosted: Fri Nov 17, 2006 4:50 am   
 
Having a closer look at the "Repeating Commands" help I had a thought, would:

#0 {This is a comment i put in my script}

be ok for a remark statement?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Nov 17, 2006 5:21 am   
 
#noop would probably be easier than that. Noop stands for No Operation, which is pretty self-explanatory :)

Theoretically that could work, but I don't think it was intended to work with 0 - it seems to be sending the command twice when I test it now.

Personally, I don't use comments all that often - I tend to have my scripts separated into quite small chunks and I can easily keep comments in the "Notes" part of the settings GUI.

EDIT: Which does actually raise a question in my mind. There's no command-line syntax for the notes field, but are they still preserved over an XML export?
Reply with quote
Oozenthor
Beginner


Joined: 31 Jul 2006
Posts: 18

PostPosted: Fri Nov 17, 2006 5:51 am   
 
Yes the #NOOP looks superior (fewer lines) when looking at the compiled code, probably execute a bit faster.

Notes are nice, but sometimes you just want to put a line in saying "I am doing this here".
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Nov 17, 2006 6:08 am   
 
Yeah... My only issue with #noop really is that it doesn't stand out with syntax highlighting like real comments do. If I am going to use a comment, I want to be able to find it again easily :P
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Fri Nov 17, 2006 7:01 am   
 
Use // for comments it works great as far as I can tell
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Oozenthor
Beginner


Joined: 31 Jul 2006
Posts: 18

PostPosted: Fri Nov 17, 2006 7:02 am   
 
I hear that, I'll have to settle for #NOOP {"comments"} , at least there is some markup.

Mind you after changing my script to all #SA / #SE / #1 / #NOOP so that now every line starts with a # the syntax highlighter has really settled down for me. Now all it is messing up is highlighting the curly braces in nested #IF statements.
Reply with quote
Zugg
MASTER


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

PostPosted: Mon Nov 20, 2006 3:27 pm   
 
Actually, instead of #1 you should be able to just do this:
Code:
{This is how I deal with @TypicalVariable}

Any command line that is surrounded in {} is forced to be sent to the script parser. Of course, this is just part of the smart command line. In a script you can just do
Code:
This is how I deal with @TypicalVariable

without the {} and it should work fine.

I wouldn't use things like #1 for this...that would be a kludge. And I definitely would *not* use #0 for commands. Nor would I use #NOOP. The existing // and ; comment characters should be used like they are intended.

Is there a reason you can't use // for comments (or ; at the beginning of a line)?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Nov 20, 2006 4:15 pm   
 
I'd had some trouble with addings comments with // making things stop compiling, but I can't reproduce it now. Probably me getting something wrong.

I've taken to using the notes field now, which suits me fine.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Zugg
MASTER


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

PostPosted: Mon Nov 20, 2006 5:57 pm   
 
I'd rather that you continued to use the // comments and then reported whatever problems you had with it so that I can fix any bugs.
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