Register forum user name Search FAQ

MUSHclient scripting

Description of MUSHclient world function: world.GetWorldById


Name GetWorldById
Type Method
Summary Gets an object reference to the world given its unique ID
Prototype IDispatch* GetWorldById(BSTR WorldID);
Description

Returns an object which can be used to refer to another world.

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.getworldbyid (id)" every time you need to get a reference to the world, and checking if it "is nothing" as in the example.

This does not apply to Lua which checks the world object every time it is used.

You could use a small variation on the examples above to write your own "send to all worlds" or something similar.


Note: Available in version 3.39 onwards.


VBscript example
' --------------------------------------------------
' Example showing sending a message to all worlds
' --------------------------------------------------

sub SendToAllWorlds (message)

dim otherworld

for each id in GetWorldIdList
  set otherworld = GetWorldById (id)
  otherworld.Send message
  set otherworld = nothing
next

end sub

SendToAllWorlds "sigh"
Jscript example
// --------------------------------------------------
// Example showing sending a message all worlds
// --------------------------------------------------

function SendToAllWorlds (message)
{
 worldlist = new VBArray(GetWorldIdList()).toArray();

 if (worldlist)  // if not empty
  for (i = 0; i < worldlist.length; i++)
    GetWorldByID (worldlist [i]).Send (message);

}

SendToAllWorlds ("say Hi there");
PerlScript example
# --------------------------------------------------
# Example showing sending a message to another world
# --------------------------------------------------

sub SendToAllWorlds {
 my ($message) = @_;

 my $otherworld;

 foreach $item (Win32::OLE::in ($world->GetWorldIdList))
 {
 GetWorldById ($item)->Send ($message);
 }

}

SendToAllWorlds ("say Hi there");
Python example
# --------------------------------------------------
# Example showing sending a message all worlds
# --------------------------------------------------

def SendToAllWorlds (message):
  worldlist = world.GetWorldIdList
  if (worldlist):
    for w in worldlist : world.GetWorldByID (w).Send (message)

SendToAllWorlds ("say Hi there")
Lua example
-- --------------------------------------------------
-- Example showing sending a message all worlds
-- --------------------------------------------------

function SendToAllWorlds (message)

  for k, v in pairs (GetWorldIdList ()) do 
    GetWorldById (v):Send (message)
  end
end

SendToAllWorlds ("say Hi there")
Lua notes
See the description for GetWorld for more discussion about using "world" variables in Lua.
Returns 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.
In Lua use the test "if ref == nil" to see if the reference is to a valid world.
Introduced in version 3.39

See also ...

Function Description
GetWorld Gets an object reference to the named world
GetWorldIdList Gets the list of open worlds - returning their world IDs
Open Opens a named document

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]

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.