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.
 Entire forum ➜ MUSHclient ➜ Tips and tricks ➜ Calling main script functions from a plugin

Calling main script functions from a plugin

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


Posted by Ked   Russia  (524 posts)  Bio
Date Wed 10 Mar 2004 03:32 PM (UTC)
Message
This topic was brought up recently: how can a function in the main script file be called from a plugin script? I've wondered about it before, but back then I decided to just expose whatever data the outside scripts may need from the plugin through MC variables. But this approach doesn't work very well if, say, you want to use the OnPluginPartialLine callback in your main script. A solution is hypothetical (though it does work for me in several other problems) but I am pretty sure it'll work:

1.Make an alias in your world file to match on something more or less unique (I prefer using GUID's or Mushclient's GetUniqueID callback). Set that alias to call a routine in your main script.

2.Whenever OnPluginPartialLine fires in your plugin, simply do World.Execute with a string that will be matched by the alias above; using alias's wildcards you can pass any needed data at the same time also.

As I said, I haven't tried that exact thing myself, but I don't see anything that would prevent it from working.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 10 Mar 2004 08:31 PM (UTC)
Message
Yes, that sounds like a brilliantly inventive way of achieving it, and would execute immediately too. Good idea.

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,788 posts)  Bio
Date Reply #2 on Wed 10 Mar 2004 11:53 PM (UTC)

Amended on Wed 10 Mar 2004 11:55 PM (UTC) by Shadowfyr

Message
Hmm.. An even better idea:

<aliases>
  <alias
   name="Sur_Send"
   script="Surname"
   match="<worldID>\:([[:digit:][:alpha:]_]) (.*)"
   enabled="y"
   regexp="y"
   send_to="12"
  >
  <send>call %1 %2</send>
  </alias>
</aliases>

Just replace the <worldID> part above with the unique ID for the world you are using it in, then the plugin can:

world.execute World.GetAlphaOption("id") & ":Some_Name " & Some_value

Since %1 and %2 directly substitute their contents, the script engine won't know the difference between a call directly coded into the script and your dynamically created one. In fact..... Since such a call inside a plugin should execute within the plugins script space, not the main one, this also solves the nasty issue of being unable to call your own custom sub, with custom parameters. The plugins alias will simply call its own sub that has the name you gave it.

Guess the CallPlugin command, that never worked all that well anyway, just became redundant. lol Really good hack Ked. I bow to your greatness and will bang my head against a wall for an hour in punishment for not figuring it out myself. ;)
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #3 on Thu 11 Mar 2004 05:07 AM (UTC)
Message
Oooo, I'd like to see that :)
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.


10,899 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.