Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Stupid Question

Stupid Question

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Duma   USA  (9 posts)  Bio
Date Fri 06 Apr 2007 01:01 AM (UTC)
Message
Ok, I know this is a stupid question and the answer might be buried in the help files, but here it goes.

How do I refer to a variable in the input screen? I don't want to have to make an alias for it, but I want to be able to just type sdk @t with t being my target.

I've tried to simply sdk @t but it takes the "@t" literally and inputs sdk @t instead of say, sdk rat. Any help would be appreciated.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 06 Apr 2007 03:05 AM (UTC)
Message
There is no provision for expanding generic @variable in the command line. It was intended for use in aliases.

However you could make a generic alias that does it for you. For example, if you are planning to type:

<some_command> @<some_variable>

... then this would work (Lua scripting):


<aliases>
  <alias
   match="^(\w+) @(\w+)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
do
  local target = GetVariable ("%2")
  Send ("%1 " .. (target or ("@%2")))
end -- do
  </send>
  </alias>
</aliases>


That looks up the variable and sends the replacement.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #2 on Fri 06 Apr 2007 05:59 AM (UTC)

Amended on Fri 06 Apr 2007 06:03 AM (UTC) by Shaun Biggs

Message
Just be careful when using this script. The mud I play on uses @ for colour codes. So @g is dark green, @G is bright green, etc. You might want to have a way to disable or escape that if you're using a variable. If you're accessing variables with @foo like zmud, you might want to have it escape with a tilde as well. The alias would be:

<aliases>
  <alias
   match="^^(\w+) (?<!~)@(\w+)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
do
  local target = GetVariable ("%2")
  Send ("%1 " .. (target or ("@%2")))
end -- do
  </send>
  </alias>
</aliases>

This will protect you from having @crush match the variable "crush" when you meant to colour rush dark cyan. You would use ~@crush instead. Might never come up, but you wouldn't want to have your script do something wacky when you don't want it to.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #3 on Fri 06 Apr 2007 09:33 PM (UTC)

Amended on Fri 06 Apr 2007 09:37 PM (UTC) by Shaun Biggs

Message
I was thinking about this a bit, and I redid the alias. Here's the result.

<aliases>
  <alias
   match="^(.*) (?<!~)@(\w+)(\W.*)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
do
  local target = GetVariable ("%2")
  Send ("%1 " .. (target or ("@%2")) .. "%3")
end -- do
</send>
  </alias>
</aliases>

That will let you have the variable pretty much anywhere on the line that you want it. However, I can't find a way to get multiple variables on one line. Is there a repeat on same line function for aliases like there is for triggers? If not, would it be better to have a somewhat recursive function called? Or just have a Lua script parsing the whole line?

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Fri 06 Apr 2007 11:35 PM (UTC)
Message
A more general solution, which you may or may not want, depending on how aggressively you want @variable to be replaced, would be to let a Lua string.gsub find and replace every occurrence of @name into its corresponding variable. This would do it:


<aliases>
  <alias
   match=".*@.*"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
Send ((string.gsub ("%0", "@([%a%d_]+)", 
      function (s)
        return GetVariable (s) or ("@" .. s) 
      end)))
</send>
  </alias>
</aliases>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #5 on Sat 07 Apr 2007 06:19 AM (UTC)
Message
That's what I was referring to when I mentioned having Lua parse the whole line. I just wanted to know if there was a better way to do that.

It is much easier to fight for one's ideals than to live up to them.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


15,217 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.