Extension to CallPlugin

Posted by Shadowfyr on Tue 13 Aug 2002 08:22 PM — 3 posts, 9,211 views.

USA #0
I recently thought about puting out a druid potion plugin companion, that would let you set the color using one of the 142 HTML names or the 665 available to unix libplot. However I ran into a snag... I also wanted to add some other things to it with the same problem. :p The routine for setting colors does this (roughly, the real code checks for correct values, etc.):

sub setcolor(name, color)
  ...
  setvariable "Pcolor_xxxx", "color"
  ...
end sub

However this would mean releasing a new version of the plugin to make it work, since CallPlugin only allows one arguement.

Why not, since a varient type can be defined as an array, add support for the following?
long CallPlugin(BSTR PluginID, BSTR Routine, Array Argument);

This need not pass the array, but rather mushclient could 'spilt' it before making the script call, thus allowing multiple arguements. It should generate the same error as trying to call the above example with 'call setcolor(blah)' or 'call setcolor(blah, blah, blah)' and thus allow an appropriate error code.

As things stand any attempt to make efficient code or add a feature without releasing a new version of the original plugin (which in my case is silly, since the new plugin does not effect the main plugins actually function).

Oh, and another reason for the companion was to allow someone who has added similar color setting to their plugin to tell the companion the id, function name and arguements needed and thus use it to provide the same name-->color matching in for it. Not to mention just looking a color up. The only function I can support using the existing calls is the last one, which would let them look up the color, but force them to use the original plugin to set it.

I can work around the problem (I supposed) by using queue to provide the needed setting, but that doesn't help with the terrain matching part I had intended to provide, since someone who is foraging may use the up arrow to queue there next move anyway and queueing the set command would mess up normal game play.
Amended on Tue 13 Aug 2002 08:25 PM by Shadowfyr
Australia Forum Administrator #1
I'm not sure that all 3 scripting engines (VBscript, JScript and Perlscript) support supplying arrays as script arguments.

For now, why not just do it yourself, eg.

world.CallPlugin "80cc18937a2aca27079567f0", "SetColour", "Pcolor_xxxx, color"

Then use "split" to split the argument into its two components.
USA #2
Umm. Well...

1. That would require redesigning the original plugin, which I was trying to avoid. I may as well put out a new version of the plugin that includes the function.

2. Second, I intended to design it so that it could be adapted to work with anyones plugin that set a color.

The easiest way I could see to do this is to pass the world.callplugin routines an array and have 'it' check to see if the variant type was an array. If it detected on, it could then send each element in the array as a 'seperate' parameter to the sub being called. Passing the array itself does not after all really solve the problem, for the same reason as problem 1.

Since you can't define the number of parameters expected when making the call, I considered this to be the best solution. It would allow you to use normal parameters with the subs, but make it possible to call them externally with more than one of them.

As for potential problems, such as mushclient not knowing the number expected.. It should generate an error like with any other case where you pass an unexpected number to the routine. It is up to the script writer to fix any miscommunications. ;)