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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Beta testing
. . -> [Subject]  World.CallPlugIn & Multiple arguments.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

World.CallPlugIn & Multiple arguments.

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


Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Sun 23 Jun 2002 02:39 AM (UTC)
Message
I am having trouble converting some of my script to work with a plugin.

Here's my original code:

Const MST = "a5446bc0345225f2bcdc5ba9"  ' ID for "Magnum Script Tools" plugin.

Dim EqItemList
EqItemList = "bweap, lweap, rweap, head, neck, arms, hands, cloak, torso, belt, legs, feet, lring, rring, shield, lhold, rhold"

' ------------------------------------------------------------
Sub EQ_Display_Inventory (thename, theoutput, arrWildcards)
	Dim arrItems
	Dim EqItem, EqStore
	Dim x
	arrItems = Split(EQItemList, ", ")
	World.Note World.GetVariable("EqTypeStatus")
	World.Note " "
	For x = LBound(arrItems) to UBound(arrItems)
		EqItem = "EQ_" & arrItems(x)
		EqStore = "EQstr_" & arrItems(x)
		World.Note PadLeft(arrItems(x), 7) & ": " & PadRight(World.GetVariable(EqItem), 30) _
		& "[" & World.GetVariable(EQStore) & "]"
	Next
	For x = 1 to World.GetVariable("TotalExtras")
		EqItem = "EQ_x_" & CStr(x)
		EqStore = "EQstr_x_" & CStr(x)
		World.Note PadLeft("Extra", 7) & ": " & PadRight(World.GetVariable(EqItem), 30) _
		& "[" & World.GetVariable(EQStore) & "]"
	Next
End Sub
' ------------------------------------------------------------

Here's the new version I am trying to implement:

' ------------------------------------------------------------
Sub EQ_Display_Inventory (thename, theoutput, arrWildcards)
	Dim arrItems
	Dim EqItem, EqStore
	Dim x
	arrItems = Split(EQItemList, ", ")
	World.Note " " & World.GetVariable("EqTypeStatus")
	World.Note "Fix Lvl: " & World.GetVariable("EqFixLevelStatus")
	World.Note " "
	For x = LBound(arrItems) to UBound(arrItems)
		EqItem = "EQ_" & arrItems(x)
		EqStore = "EQstr_" & arrItems(x)
		World.Note World.CallPlugIn MST, "PadLeft", arrItems(x), CStr(7) _
		& ": " & World.CallPlugIn MST, "PadRight", World.GetVariable(EqItem), CStr(30) _
		& "[" & World.GetVariable(EQStore) & "]"
	Next
	For x = 1 to World.GetVariable("EQTotalExtras")
		EqItem = "EQ_x_" & CStr(x)
		EqStore = "EQstr_x_" & CStr(x)
		World.Note World.CallPlugIn MST, "PadLeft", "Extra", CStr(7) & ": " _
		& World.CallPlugIn MST, "PadRight", World.GetVariable(EqItem), CStr(30) _
		& "[" & World.GetVariable(EQStore) & "]"
	Next
End Sub
' ------------------------------------------------------------


Error number: -2146827263
Event:        Execution of line 2179 column 31
Description:  Expected end of statement
Line in error: 
		World.Note World.CallPlugIn MST, "PadLeft", arrItems(x), CStr(7) _
Called by:    Immediate execution

I'm assuming "World.CallPlugin" is built to only accept one argument?

I'm beginning to wonder if it's really worth keeping a library of short, but common subroutines. Perhaps I should just use an "include" directive in the XML file instead (waste of memory if multiple plugins all use the same include file though). Also, I could just duplicate the routines directly in the script of each plugin...

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #1 on Sun 23 Jun 2002 02:53 AM (UTC)

Amended on Sun 23 Jun 2002 02:55 AM (UTC) by Magnum

Message
I realized there might be a problem in that new code, with some of the strings running together (that I didn't intend), so I tried this instead:

		World.Note CStr(World.CallPlugIn MST, "PadLeft", arrItems(x), CStr(7)) _
		& ": " & CStr(World.CallPlugIn MST, "PadRight", World.GetVariable(EqItem), CStr(30)) _
		& "[" & World.GetVariable(EQStore) & "]"

...Essentially wrapping each 'CallPlugin' within a 'CStr()' in order to maintain the order of operations I want.

The error I get now is ")" expected.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #2 on Sun 23 Jun 2002 03:12 AM (UTC)
Message
Here's the plugin it is referring to:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient []>

<!--	===============================================================
		SCRIPT TOOLS

		This plugin is a library of assorted script subroutines that
		are general purpose, and may be called from a variety of other
		plugins.

		=========================================================== -->

<muclient>
<plugin
	name="Magnum_Script_Tools"
	version = "0.01"
	author="Magnum"
	language="vbscript"
	id = "a5446bc0345225f2bcdc5ba9"
	purpose = "General purpose script routines."
	save_state = "n"
	date_written = "2002-06-14"
	date_modified = "2002-06-22"
	>

<description trim="y">
<![CDATA[
This plugin contains assorted script routines that are general
purpose, and may be called by other plugins.

All plugins created by MAGNUM will require that this plugin
also be installed.

Version: 0.01
]]>
</description>
</plugin>

<script>
<![CDATA[

' ------------------------------------------------------------
'   EMULATE ARRAY using MUSHclient variables
'
' Note that MCDelArray will delete ALL MushClient variables
' that start with the string passed in "ArrayName", with an
' "_" appended.
' ------------------------------------------------------------
Sub MCSetArray (ArrayName, ArraySize, TheValue)
	Dim arrPointers
	Dim x
	arrPointers = Split(ArraySize, ",")
	For x = LBound(arrPointers) to UBound(arrPointers)
		ArrayName = ArrayName & "_" & CStr(arrPointers(x))
	Next
	World.SetVariable ArrayName, TheValue
End Sub

Function MCGetArray (ArrayName, ArraySize)
	Dim arrPointers
	Dim x
	arrPointers = Split(ArraySize, ",")
	For x = LBound(arrPointers) to UBound(arrPointers)
		ArrayName = ArrayName & "_" & CStr(arrPointers(x))
	Next
	MCGetArray = World.GetVariable(ArrayName)
End Function

Sub MCDelArray (ArrayName)
	Dim VariableList
	Dim StringPos
	Dim x
	VariableList = World.GetVariableList
	ArrayName = ArrayName & "_"
	For x = LBound(VariableList) to UBound(VariableList)
		StringPos = InStr(1, VariableList(x), ArrayName, vbTextCompare)
		If StringPos = 1 Then
			World.DeleteVariable VariableList(x)
		End If
	Next
End Sub

' ------------------------------------------------------------
'   STRING MANIPULATION
' ------------------------------------------------------------
Function PadLeft (String, Length)
	Dim StringLength
	StringLength = Len(String)
	If StringLength < Length Then
		String = Space(Length - StringLength) + String
	End If
	PadLeft = String
End Function

Function PadRight (String, Length)
	Dim StringLength
	StringLength = Len(String)
	If StringLength < Length Then
		String = String + Space(Length - StringLength)
	End If
	PadRight = String
End Function
' ------------------------------------------------------------
Function TimeDiff (StartTime, EndTime)
	Dim Hours, Minutes, Seconds
	Seconds = DateDiff("s", StartTime, EndTime)
	If Seconds > 90000 Then Seconds = 90000
	If Seconds < 0 Then Seconds = 0
	Minutes = Seconds / 60
	Minutes = Fix(Minutes)
	Seconds = Seconds - (Minutes * 60)
	Hours = Minutes / 60
	Hours = Fix(Hours)
	Minutes = Minutes - (Hours * 60)
	Seconds = CStr(Seconds)
	Minutes = CStr(Minutes)
	Hours = CStr(Hours)
	If Len(Seconds) = 1 Then Seconds = "0" + Seconds
	If Len(Minutes) = 1 Then Minutes = "0" + Minutes
	If Len(Hours) = 1 Then Hours = "0" + Hours
	TimeDiff = Hours & ":" & Minutes & ":" & Seconds
End Function

' ------------------------------------------------------------
'   LOGGING
' ------------------------------------------------------------
Sub LogSend (SendString)
	Dim Preamble, Postamble
	Dim CommandColour
	World.Send SendString
	If World.GetOption("log_html") Then
		CommandColour = World.CustomColourText(World.GetOption("echo_colour"))
		Preamble = World.GetAlphaOption("log_line_preamble_input")
'		Preamble = Preamble & "<font color='" & CommandColour & "'>"
		Postamble = World.GetAlphaOption("log_line_postamble_input")
'		Postamble = "</font>" & Postamble
		World.WriteLog Preamble & World.FixupHTML(SendString) & Postamble
	Else
		World.WriteLog SendString
	End If
End Sub

' ------------------------------------------------------------
'   PUSH COMMAND
' ------------------------------------------------------------
Sub SetCommandLine (CommandString)
	World.PushCommand
	World.SetCommand CommandString
	World.SelectCommand
End Sub

' ------------------------------------------------------------
' ------------------------------------------------------------

]]>
</script>

The whole Emulating errays here is probably a waste of time, since they would exist in their own namespace, meaning I would have to update my script to grab variables across namespaces. So much of a pain in the ass... I think I'll just kill this plugin, and copy the routines individually into each script/plugin file.

(I haven't gotten to testing out those routines, trying to fix the one I mentioned above first).

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #3 on Sun 23 Jun 2002 07:22 PM (UTC)
Message
Hmm.. Well if this was qbasic I would have suggested a variable type called literally a 'TYPE'. This allowed you to pass multiple values in a single variable as though they where one and retrieve them through Variable.subvariable. However looking at the help for VBscript it looks like they only support a few specific types and those deal with files and directories, etc. :p In theory you 'might' be able to pass a sub directly as though it where a true object, but I haven't a clue how or if vbscript supports scope, besides automatically for global and local variables.

There is a variable type called a vbDataObject that may be the equivalent of the old qbasic types, but the help give absolutely no info on it. :p

Note... There is one really vague example of scope used.. A subroutine that called another like:

Debug.Print A

But it doesn't explain the limits of this or even give a clear example of where Debug is defined. :p

This is really annoying.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 25 Jun 2002 01:43 AM (UTC)
Message
Quote:

I'm assuming "World.CallPlugin" is built to only accept one argument?


You don't need to assume, it is described that way on the functions page.

But yes, the answer is the prototype is:


long CallPlugin(BSTR PluginID, BSTR Routine, BSTR Argument);


As far as I know COM objects have to have a predefined number of arguments, so I have allowed for one. The idea of passing multiple values as an array or something won't work, as the argument is defined as a string.

However, you could make your own "multiple" argument by putting a delimiter between strings (eg. tab, tilde, hex 0x01) and then using "split" in the called routine to break them up again.

Alternatively, use the "include" approach, which lets you include functions, which can then have as many arguments as you want.

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #5 on Tue 25 Jun 2002 06:43 PM (UTC)
Message
There is probably a way to do this in true COM, i.e. a C++/VB program. You would probably pass the entire list in a string then at either end have it 'cast' into a structure. In qbasic you could do:
[code]type MyData
int Mynumber
string * 5 Myname
real Myothernumber
end type

common InData as MyData[/code]
Qbasic simply read the same number of fixed bytes from the file each time and stored it in InData, or the reverse for writing. This was often very helpful to have and I am sure there is some way to do it within full languages, but sadly not in vbscript. I wouldn't mind seeing some similar sort of prototyping built in as a client feature though. It is a lot easier to pass a single variable containing all the data, than have to use a mess of individual parameters, especially if as in this case you can't even use them.

As to syntax... How about>

World.DefineType "Name","Types"

Where types are:
R(vname) - Real.
I(vname)- Int.
L(vname)- Long Int.
D(vname) - Double Real.
S#(vname) - Strig of # characters.
...anything I missed...

Vname being the internal name of the internal 'variables'. Then:

NewVar = World.TypeCast "Name",BSTR YourVar, "vname"

Would return a value from the variable you pass it as the specified type.

Possible errors -
Not a defined type.
Variable is incorrect length to be cast.
..whatever else is appropriate..

Of course.. I assume that strings have a) null terminatation and b) length. i.e. they don't look for the null as 'end of string'. If they do then some potential problems are possible, but it should work, even if it is a little nastier than the qbasic 'name.vname' implimentation. ;)
[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.


6,350 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 FutureQuest]