[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  form of Execute that returns a string?

form of Execute that returns a string?

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


Posted by Brian   (3 posts)  [Biography] bio
Date Tue 16 Nov 2010 05:23 PM (UTC)
Message
Is there a function similar to Execute that returns a concatenatable string, rather than sending directly to world?

I am trying to make an alias that is capable of executing other aliases, and appending the output to another string, for ordering charmed followers. i.e., if I have an alias:
fs *

which sends:
cast 'flame shroud' %1

Then I would like to be able to have a second alias that lets me do something like:
oc fs *
and have it send:
order charmie cast 'flame shroud' %1
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 16 Nov 2010 08:43 PM (UTC)

Amended on Tue 16 Nov 2010 08:44 PM (UTC) by Nick Gammon

Message
There is no such function right now, nor is it particularly easy to do. The reason is, aliases don't just substitute one string for another. For example, aliases can call scripts, the scripts can send stuff to the MUD, open files, read databases, put things on the screen, play sounds, etc. There isn't any easy way of "capturing" all that into a string that can be concatenated later with something else.

If this is inside a plugin you could work around it a bit. If you read up on the OnPluginSend plugin callback, you will see that this can be used to find what would be sent to the MUD, and decline to send it. So your general technique could be:


  • In your second alias:


    • Set a flag (eg. deferred_send = true)

    • Save what you want to prepend somewhere (eg. extra_stuff = "order charmie")

    • Do your "fs %1" - this will attempt to send "cast 'flame shroud' mobname" to the MUD

    • Clear the flag (eg. deferred_send = false)


  • In OnPluginSend, test if the flag (deferred_send) is true. If not, just return true, so the message is sent to the MUD.

  • But if the flag is set, grab the saved extra stuff ("order charmie"), concatenate with what was going to be sent ("cast 'flame shroud') and do a Send to send the combined command.

  • Now return false so the original command is not sent


So OnPluginSend might look like this (I haven't tested this):


function OnPluginSend (sText)
  if deferred_send then
    Send (extra_stuff .. " " .. sText)
    return false -- don't send original
  end -- if

  return true  -- process it
end -- function



And your alias might do this (in a script):


deferred_send = true
extra_stuff = "order charmie"
Execute ("fs %1")  -- evaluate "fs" alias
deferred_send = false


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Brian   (3 posts)  [Biography] bio
Date Reply #2 on Wed 17 Nov 2010 11:54 AM (UTC)
Message
Awesome, that works great -- thanks a ton!
[Go to top] 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.


8,354 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]