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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Yvain
Newbie


Joined: 09 May 2008
Posts: 4

PostPosted: Sat May 10, 2008 1:24 am   

%if statement returns not parsing?
 
Hello,

I am having some problems transferring my zMUD script over to cMUD, and while most are documented in the help files, one particular problem is not.

Specifically, it would seem that now the value returned to the MUD by the %if command is no longer "parsed" by cMUD as it used to be by zMUD. In short, if an %if command returns an alias name, it will simply send the name to the MUD and not actually execute it (whereas in zMUD it would do both).

While most of my logic uses the #if command, the main "stacks" use %if for brevity's sake, and now these are no longer functional.

Is this perhaps due to an option I should enable? Or is it an undocumented change (or perhaps I simply missed the documentation, of course)?

Thank you.

Yvain
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat May 10, 2008 1:26 am   
 
Perhaps you could show us an example of you using this %if statement that's not functional.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Yvain
Newbie


Joined: 09 May 2008
Posts: 4

PostPosted: Sat May 10, 2008 2:15 am   
 
Well, it's nothing special. For example:

%if(@Hurt = 1,dh)

Where dh is an alias that makes you drink a health potion.

Now it simply sends "dh" to the MUD, and I would have to replace dh with "drink health" for it to work. Unfortunatly, some of the aliases called in these %if stacks are actual procedures, not simple commands.

I know I could just switch everything over to #ifs, but I would prefer to avoid that if possible.

Yvain
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat May 10, 2008 2:19 am   
 
Use %alias to expand the dh alias
Code:
%if(@Hurt = 1,%alias(dh))


Nothing special but it made it clear.
You might know what you're talking about, but if you don't demonstrate I might not
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat May 10, 2008 2:22 am   
 
EDIT: Ninjad. Your problem is this one. The solution, as I mention below, is to use #exec:

#exec %if(@hurt=1,dh)

though doing it this way:

#if (@hurt=1) {dh}

would be better. If you're doing a lot of if...elseif...ing, try the #switch command instead.

---

It does indeed depend on how you're using it. If you're using the #send command, that'll be your problem - #send no longer parses aliases but parses commands the same as they otherwise would be (for oninput triggers etc). To send stuff directly to the MUD, as the old #send command did, you should now use #sendraw. For full parsing, including aliases, you should now use #exec.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat May 10, 2008 2:30 am   
 
Yeah doing it my way would only expand the body of the alias command, so you would still need to use #exec
Fang's right the way that you're trying to avoid is really the best way to do it.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Yvain
Newbie


Joined: 09 May 2008
Posts: 4

PostPosted: Sat May 10, 2008 2:42 am   
 
Ah, excellent. The switch command is definitely something I was looking for, to replace the bulky stacked %ifs (and #ifs, for that matter, though I rarely stack those).

It'll take some rewriting, but at least for now I can use the #exec command to get things working quickly (I hope).

Thank you.

Yvain
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat May 10, 2008 3:11 am   
 
I suggest using #if rather than #exec because the #exec command takes a string argument - its argument is compiled at runtime, every time. The #if command (and the alias in it) are compiled once each time you log in (or when you've changed something etc), and after that the compiled code is used instead. So it's much faster to avoid #exec.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Yvain
Newbie


Joined: 09 May 2008
Posts: 4

PostPosted: Sat May 10, 2008 3:18 am   
 
I have another question: is there a way to override a hotkey with a macro?

In zMUD I use CTRL-` as an important macro, and I'd rather not have to rework my control scheme.

Yvain
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat May 10, 2008 3:44 am   
 
There's a preference Macros override menu shortcuts, but there are some things it doesn't work on. It's worth a go, though.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat May 10, 2008 3:49 am   
 
It depends. There are some macro combinations that are OS-centric and they represent an UI standard (for example, CTRL-V is the universal paste command). These aren't usually overridable, and even when they might be you're likely to get dual results instead of one or the other--the Windows activity as well the stuff you wrote.

As long as there's no UI standard thing going on, though, your custom code should win out if you have the Macros Override Menu Shortcuts preference set.
_________________
EDIT: I didn't like my old signature
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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