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
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed Feb 20, 2008 2:15 am   

Odd behavior of #EXECWIN (IMO)
 
If I try to execute this code using #EXECWIN different things will happen depending on how the object of the command is presented:
Code:

#EXECWIN @main {pcan;run su}

works fine; it first sends the alias pcan, which gets expanded and executed, and then the string "run su" is sent and executed.
However, if I do the following:
Code:

sw = "pcan;run su"
...
...
#EXECWIN @main {@sw}


or if I have a string list @swlist = "pcan|run su" and I try this:
Code:

#FORALL @swlist {#EXECWIN @main {%i}}

the alias will be sent as a command but it will not be expanded. The string "run su" does get executed.

Also, this will fail to work:
Code:

#LOOP %numwords(@sw,";") {#EXECWIN @main {%word(@sw,%i,";")}}

What is really peculiar is that the mapper reacts to the alias, which in turns excutes another alias, wich ends up executing a #TELEPORT. So the map location is presented correctly. Though, the "pcan" is sent to the MUD unexpanded.

In addition:
Code:

#VAR x "s;w"
#EXECWIN @main {@x}

will send the string s;w to the MUD. Not the commands "s" and "w".

The question is, then, what am I doing wrong?
Also, is there a way to force expansion?
Reply with quote
Tech
GURU


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

PostPosted: Wed Feb 20, 2008 5:30 am   
 
I didn't get a chance to confirm what you're experiencing. But the first thing that jumps to mind is to try %expand
_________________
Asati di tempari!
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed Feb 20, 2008 6:15 am   
 
First thing that jumped to my mind, also. However, %expand, in this case, returns the string asis.
For instance:
Code:

#VAR sw "pcan;run su"
#ECHO %expand(@sw)

sends this to the screen: pcan;run su
which is the string I started with and has the same problem when used as the object of #EXECWIN
Reply with quote
Tech
GURU


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

PostPosted: Wed Feb 20, 2008 1:30 pm   
 
What about %alias then?
_________________
Asati di tempari!
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Feb 21, 2008 3:38 am   
 
OK, I tried %alias. Two problems with that. Firstly, the alias pcan invokes an alias. What was sent to the MUD was the invoked alias, which of course, wasn't executed for the same reason that started this problem to begin with. Secondly, CMUD crashed with an access violation trying to read location absolute 0.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Feb 21, 2008 5:27 am   
 
What I was hoping, but doesn't seem to be the case, is that #EXEC and #EXECWIN would behave exactly the same. That is, that #EXEC was just a shortcut of #EXECWIN for sending commands to the default window. What I am trying to do is to move much of my script output (which consists of clickiable #MXP output much of the time) to a (floating) window, keeping the main window uncluttered. But with this odd behavior, I am going to have to rethink this. Unless I am very much msitaken (and that can never be ruled out!), commands to the MUD must be sent to the main window.
Reply with quote
Tech
GURU


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

PostPosted: Thu Feb 21, 2008 6:23 am   
 
Alright.. I finally got a chance to play around with this and I think figured out what's happening. The command is working as expected.

I think the problem you are having ( which was the same mistake I was making at first ) is that you are forgetting the default scope of the window is private.

When you #EXECWIN it executes in the scope context of the window. So if you variable @main is 'test' then alias etc. will only execute from the scope of the test window. Now all window scopes are private so if the alias you want to execute is in another window (or for that matter a private module) the 'test' window won't know about it, thus the text is just echoed to the screen. To correct this problem you have a few options.

The first, and the one I recommend is to move the alias 'pcan' and any other you need into a global module. The second is you can copy the needed aliases to the child window (this is less flexible for obvious reasons). Third you can explicitly refer to the alias using the //WindowOrModuleName/VariableFunctionOrAliasName syntax. So if the alias 'pcan' was under the 'MyMud' window, in you'd have the follow in your swlist variable.
Code:
sw = "//MyMud/pcan;run su"


As I said, I recommend option one.

To the Gurus, I'll summarize the situation here and try to call out the nuance of the command in the help comments. Of course if you beat me to it, that will be fine too. Very Happy
_________________
Asati di tempari!
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Feb 21, 2008 6:32 am   
 
You are the wizard and I am the novice, so option 1 it is!. Thanks, Tech.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Feb 21, 2008 11:00 am   
 
OK, I tried moving all the pertinent classes into a separate module such that:
Code:
#EXECWIN MUDTraversal {@sw}

This result is the same. If I use the default window's name, then nothing happens. However, using overkill works...
Code:
#ALL {@sw}
does the job, but I have a suspicion this not the way to go. I also suspect that I may be misunderstanding what you told me. MUDTraversal is a global module but I placed it under the
_________________
Sic itur ad astra.
Reply with quote
Tech
GURU


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

PostPosted: Thu Feb 21, 2008 2:39 pm   
 
This is the general format of #EXECWIN
Code:
#EXECWIN MyWindowName {Command list}


So if the the window you want the commands run in is in the @main variable, you would still execute it as before.
Code:
#EXECWIN @main {@sw}


or if the Window you wanted to run in was called 'ChildWindow' you could use that window name explicitly like so.
Code:
#EXECWIN ChildWindow {@sw}
_________________
Asati di tempari!
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Fri Feb 22, 2008 2:14 am   
 
Yes, @main is the way to go. When I first tried it, the variable showed as undefined so I moved it to the module and that was causing the problem. I moved it back to the package and external to the module. I am sure that the scope is something that I needed to address and I have done that. However, the problem is not solved. I re-state here that if I substitute
Code:
#EXECWIN @main {@sw}
where
Code:
sw = "pcan;run su"
with
Code:
#EXECWIN @main {pcan;run su}
then it works. So the problem is that by giving #EXECWIN a string variable as the object, it is getting thrown off by the implied quotes or simply by the fact that it expects a raw command string. In the case where I explicitly put the commands separated by ";", there were no delimiting quotes and it worked. One thing that supports the argument is the fact that the Editor puts the unquoted object of #EXECWIN in black and it works, but if I put a quoted string as the object, it paints it green and the execution fails. Though I note here that @sw is explicitly declared as a Expanded String, changing the declaration to Autotype makes no difference.
_________________
Sic itur ad astra.
Reply with quote
Tech
GURU


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

PostPosted: Fri Feb 22, 2008 2:22 am   
 
Try this

Code:
#EXECWIN @main {#exec @sw}
_________________
Asati di tempari!
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Fri Feb 22, 2008 3:05 am   
 
Very clever, Tech. Should have thought of it myself. The sense of it is obvious and it does work. This means that #EXECWIN does expect a raw command, perhaps the help file should reflect this. Thank you very much for your help.
_________________
Sic itur ad astra.
Reply with quote
Tech
GURU


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

PostPosted: Fri Feb 22, 2008 6:55 am   
 
Out of curiousity, what does your signature mean?
_________________
Asati di tempari!
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Fri Feb 22, 2008 6:59 am   
 
It means "Thus you shall go to the stars". A quote from Virgil's Aeneid. Wink
_________________
Sic itur ad astra.
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