CallPlugin and multiple parameters.

Posted by Shadowfyr on Fri 20 Sep 2002 06:38 AM — 3 posts, 16,178 views.

USA #0
Well since there seems to be no real way to do this with the call. I have come up with this instead>

'==========================================================================================
'Latch for External plugin calls.
'
'Call syntax is "Name(Param,Param2,...)"
' i.e. CallPlugin "22ca9b6ff9d79f1a8e9f5895","CallLatch","Potion_Setcolor(title,#B0F080)"
'==========================================================================================
'NOTE: A call that uses () and (something) will both produce 1 parameter. Make sure you
'have error checking in the sub you call from here to deal with invalid values. ;)
'==========================================================================================
sub CallLatch (CallInf)
  dim temp,params,npar
  temp = split(CallInf, "(")    'Break things up at the first bracket, so temp(0) is the Sub and temp(1) is params.
  if ubound(temp) = 1 then      'If there are any parameters, remove the ) and split them into seperate bits.
    temp(1) = replace(temp(1),")","")
    params = split(temp(1),",")
  end if
  select case temp(0)   'Check against the Sub name to find a match.
    case "Potion_Setcolor"   ' Check against the first valid sub (this can be anything, but
                             ' is less confusing if it matches the real name).
      npar = 2   'How many parameters should there be?
      if ubound(params) <> npar - 1 then   'Test npar - 1 (arrays are 1 less than the 'real'
                                           'number of parameters. If it fails show an error.
        world.colournote "Red","Black", "Error: Invalid call to CallLatch in " & world.getpluginname & "."
        world.colournote "Red","Black", "Call was " & CallInf
        world.colournote "Red","Black", "  Error -- Invalid number of parameters. Should be " & npar & "."
        world.colournote "Red","Black", " "
      else   ' Everything looks OK, so lets make the real call here.
        call Potion_Setcolor(trim(params(0)),trim(params(1)))
      end if
    case else   'This is if we mis-spell are sub name in the other plugin/script or we
                'Tried to call a sub this plugin doesn't support.
      world.colournote "Red", "Black", "Error: Invalid call to CallLatch in " & world.getpluginname & "."
      world.colournote "Red", "Black", "Call was " & CallInf
      world.colournote "Red","Black", "  Error -- No such routine can be called."
      world.colournote "Red", "Black", " "
  end select 
end sub


This comes straight out of some upgrades I am making to a plugin and if used right will 'fake' a real call. Though it does require that you add your own test and error messages, etc. ;)
Amended on Fri 20 Sep 2002 06:44 AM by Shadowfyr
#1
Why not just send through an array as your single parameter?
USA #2
I could have, but this way you 'seem' to be calling the exact routine that is used internally by the plugin. But also, according to Nick it is not technically allowed, since he is not sure if all script types support such an array.