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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ VBscript ➜ Library script files?

Library script files?

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


Posted by Magnum   Canada  (580 posts)  Bio
Date Tue 01 Jan 2002 04:22 PM (UTC)
Message
Well... My script file is getting large enough, that I am considering breaking it into smaller pieces.

One advantage, is that when I want to edit a portion of the script, I would not have to scan the entire script looking for it. Also, there are parts of my script that I would not mind sharing, and other parts I would like to keep private. This would be easily accomplished if different sections of the script were in different files.

It's been a while since I worked with library files, and when I did, it was in PASCAL.

Nick, could you offer any insights please?

Is it possible to use library files from the MushClient script file?
Is there anything I should be aware of regarding the matter? (Any reminders)?

Any recommended links for places to learn about coding using library files?

Thanks in advance. :)

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

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Krenath   USA  (76 posts)  Bio
Date Reply #1 on Tue 01 Jan 2002 05:03 PM (UTC)

Amended on Tue 01 Jan 2002 05:06 PM (UTC) by Krenath

Message
This is one I asked about a while back. To my knowledge, this currently has the status "Suggestion for Future Enhancement"

In theory, all that would be needed would be a simple scripting directive which told MUSHclient (in effect) "Before you do anything else, load the contents of file X and put it right here". MUSHclient, while loading the main script file, would assemble all the library files (In ASP, they're "Include files, so that's how I refer to them) in memory and pretend they're a single script file, to be parsed normally.

This would require additional passes over each of the script files by MUSHclient, *recursively* looking for INCLUDE directives. Once MUSHclient has found and (in memory) replaced the INCLUDE directives with the contents of all the script files, it would then pass it to the script engine.

Then you could take all the MUSHclient constant definitions, stuff them into an include file and put that in a central location to be referenced by your individual world script files, allowing you the ability to edit single files and update the scripts for all your worlds at once.


- Krenath from
bDv TrekMUSH
ATS TrekMUSH
TNG TrekMUSE
TOS TrekMUSE
Top

Posted by Dubthach   (47 posts)  Bio
Date Reply #2 on Wed 02 Jan 2002 03:24 PM (UTC)
Message
This is not a failure of MushClient. I don't know how VBScript includes work, but I routinely use various Perl modules in my script file. Figure out how to include things in VBScript, and just try it out.

If you can't figure it out...switch to Perl!
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #3 on Sun 13 Jan 2002 03:53 PM (UTC)
Message
This is still something I would like to try out, but I can't seem to find any help files on the matter.

I don't know if it's just me, but I find Microsoft's site very hard to navigate. I can't find anything useful there after searching for quite some time.

Could someone at least point me in the right direction? In VBS, is the command called "include", or is it some other word?

Once again, if you know of any good sites that teach VBS, please offer them. I would ESPECIALLY be interested in any site that offers a glossary of all VBS terms, where you just click on the word and learn about the function...

Unfortunately, doing a search at Google on phrases like:

"visual basic" glossary include

...net me a result of tons of useless links.

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

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Sun 13 Jan 2002 09:36 PM (UTC)
Message
I haven't found a VB "include" directive, but if someone knows of it I would be very interested too. :)

- Nick Gammon

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

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #5 on Mon 14 Jan 2002 11:52 AM (UTC)
Message
I looked up some of my old PASCAL programming from 10 years ago...

In PASCAL, it's the "USES" directive.

I would like to thing BASIC has it's own version of this directive.

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

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Shadowfyr   USA  (1,790 posts)  Bio
Date Reply #6 on Tue 15 Jan 2002 08:36 AM (UTC)
Message
OK. First (forgot I even had this) - http://msdn.microsoft.com/scripting/vbscript/download/vbsdoc.exe

Tis contains a complete reference for VBScript V5.5. ;) Though I am not sure what the 'current' version is or where to find the help for it. Frankly, even this one may be missing by now. :p

And second, as near as I can tell there is no direct way to include a secondary script. I suspect this is because of the fact that it was designed for web pages initially, so didn't need the include directives. These are 'usually' compiler directives and not supported by interpretted languages. Perl was probably created by programmers for who the idea of leaving out such directive would never had been a consideration. The only ability I could see in the docs for VBScript to include anything of the sort was COM objects and that is a big can of worms, since there are like 3 different types and they all have to be registered before using them.

However the full Visual Basic 6 does have an include directive (not that it helps any of us). ;)
Top

Posted by Krenath   USA  (76 posts)  Bio
Date Reply #7 on Tue 15 Jan 2002 03:00 PM (UTC)
Message
Oh! Hang on! There *IS* a way.

Exec and Eval, which are relatively new to VBscript, can be used to execute text strings as code. And these text strings will be executed in the scope of the running script, so if you EXEC a text string that contains function definitions, you'd be able to call them later in your code, and the function could be able to call subroutines and functions defined in your main file.

Unfortunately, you can't just hand it a filename. It takes a text string as a parameter. You could, however, use the Scripting.FileSystemObject to open the 'include' file, ReadAll the contents, then EXEC the script.

I'll try it and see how well it works.

- Krenath from
bDv TrekMUSH
ATS TrekMUSH
TNG TrekMUSE
TOS TrekMUSE
Top

Posted by Shadowfyr   USA  (1,790 posts)  Bio
Date Reply #8 on Tue 15 Jan 2002 08:21 PM (UTC)
Message
Interesting idea. I saw that, but didn't look at it too close. It should be noted that looking at documentation that came with my new VB 6.0 and include stuff for VBScript, there are commands to make functions and subs 'global' or 'private', to allow or prevent 'other scripts' calling them. This seems to imply what I thought before. The assumption of those who developed VBScript was web design and servers, both of which allow you to load multiple scripts through the server or through html. Therefore there was never a reason for them to add an include directive, since it is assumed that the 'client' or 'server' supports loading and execution of multiple scripts and the communication between them.

Again, not too helpful. Mushclient is however slightly flawed in this regard, in as much that scripts do not appear to run in a seperate thread and can actually stop the client while they execute a long loop or similar tasks. This makes both multiple scripts and some addons a bit problematic. This is in fact especially true of an idea I had, which without multithreading would bring mushclient to a screeching halt for several seconds at the absolute least, while it processed the data.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #9 on Tue 15 Jan 2002 09:46 PM (UTC)
Message
Scripts generally need to run in the current thread so things get done in an orderly way. :)

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,790 posts)  Bio
Date Reply #10 on Wed 16 Jan 2002 04:49 AM (UTC)

Amended on Wed 16 Jan 2002 04:52 AM (UTC) by Shadowfyr

Message
Yeah, that is true..

In any case, the plugin model someone else mentioned looks to be the most likely option, since some sort of multiple script support is needed and most people appear to like the ones that don't support #include directives. Figures.. lol
Top

Posted by Krenath   USA  (76 posts)  Bio
Date Reply #11 on Thu 17 Jan 2002 06:34 PM (UTC)
Message
The following code will indeed include script from other files:

Function GetFileContents(sFileName)
	Dim fso,file
	Set FSO = CreateObject("Scripting.FileSystemObject")
	Set File=FSO.OpenTextFile(sFilename,1)
	GetFileContents=File.ReadAll
	Set File = Nothing
	Set FSO = Nothing
End Function

World.Note "Including File 'include.vbs'"
Execute GetFileContents("C:\Program Files\MUSHClient\Include.vbs")

The Execute statement *must* be outside all subroutines and functions if the included file's code is to be available to all subroutines and functions. You could use it inside subs or functions if you purposefully wanted to limit the scope.

the OnWorldOpen, OnWorldConnect, OnWorldClose, and OnWorldDisconnect subroutines must be defined in the main script file MUSHclient loads, as it verifies these subroutines exists before it parses the file. Likewise, any constants that are used before the Execute statement is , uh, executed need to be in the main script file.

Editing your library files will not cause MUSHclient to reload or prompt to reload your script. You must do this manually upon changes.

It would be *extremely* easy to search a directory for all script files and execute them all, thereby automatically loading plugin files. I'll post something on this later.

- Krenath from
bDv TrekMUSH
ATS TrekMUSH
TNG TrekMUSE
TOS TrekMUSE
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #12 on Thu 17 Jan 2002 08:11 PM (UTC)
Message
Great suggestion!

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


38,117 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.