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

MUSHclient scripting

Description of MUSHclient world function: world.Open


Name Open
Type Method
Summary Opens a named document
Prototype IDispatch* Open(BSTR FileName);

View list of data type meanings

Description

Returns an object which can be used to refer to the new document (except in Lua, see below).

You should be very cautious about storing the object reference of the world in a global variable, because if the world is closed then that reference becomes invalid, which will very likely lead to an access violation (program crash). You are better off using "world.getworld (name)" every time you need to get a reference to the world, and checking if it "is nothing" as in the example.

Better still, use "world.GetWorldById (id)" which uses each world's unique ID, in case you have multiple worlds of the same name.

You can use Open to open either a MUSHclient world (ie. a MCL file) or a text file (ie. a TXT file).

If the named document is already open then "open" does *not* open another copy, rather it activates that document (brings it to the front).

VBscript example
dim otherworld

  set otherworld = world.open  ("smaug.mcl")

  if not (otherworld is nothing) then
    otherworld.send "say hello everyone" 
  end if
Jscript example
var otherworld

   otherworld = world.Open ("smaug.mcl");

  if (otherworld != null)
   otherworld.send("say hi there everyone");
PerlScript example
my $otherworld;

 $otherworld = $world->Open ("smaug.mcl");

  if (!defined ($otherworld))
    { 
   $otherworld->send("say hi there everyone");
    }
Python example
var otherworld

   otherworld = world.Open ("smaug.mcl")

  if (otherworld != null)
   otherworld.send("say hi there everyone")
Lua example
openedOK = world.Open ("smaug.mcl")   -- true or false
Lua notes
Lua is not implemented using the COM model, and thus opening a file and getting an object reference is not possible.

As of version 4.08 however, it will attempt to open the file in the same way as other languages, and return true if it succeeded, and false otherwise.

If you want a "world" userdata to refer to after opening a world, you would need to use GetWorld or GetWorldById to get a reference to the newly-opened world.
Returns For Lua, it returns true if the file was opened OK, and false if not.

For other languages:

An object reference to the named world, if it was found.
Otherwise NULL.

In Vbscript use the test "is nothing" to see if the reference is to a valid world.
In JavaScript use the test "== null" to see if the reference is to a valid world.
In PerlScript use the test "defined ()" to see if the reference is to a valid world.

See also ...

Function Description
Activate Activates the world window
GetWorld Gets an object reference to the named world
GetWorldList Gets the list of open worlds - returning their world names
OpenBrowser Opens a supplied URL in your default web browser

Search for script function

Enter a word or phrase in the box below to narrow the list down to those that match.

The function name, prototype, summary, and description are searched.

Search for:   

Leave blank to show all functions.


Return codes

Many functions return a "code" which indicates the success or otherwise of the function.

You can view a list of the return codes


Function prototypes

The "prototype" part of each function description lists exactly how the function is called (what arguments, if any, to pass to it).

You can view a list of the data types used in function prototypes


View all functions

[Back]

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]