GetWorldById
Script function

world.GetWorldById

DOC_scripting Read about scripting

Type

Method

Summary

Gets an object reference to the world given its unique ID

Prototype

IDispatch* GetWorldById(BSTR WorldID);

DOC_data_types View list of data type meanings


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.



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.



Return value

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.




See Also ...

Topics

DOC_scripting Scripting
DOC_world World functions

Functions

FNC_GetWorld GetWorld (Gets an object reference to the named world)
FNC_GetWorldIdList GetWorldIdList (Gets the list of open worlds - returning their world IDs)
FNC_GetWorldList GetWorldList (Gets the list of open worlds - returning their world names)
FNC_Open Open (Opens a named document)
FNC_OpenBrowser OpenBrowser (Opens a supplied URL in your default web browser)

(Help topic: function=GetWorldById)

DOC_contents Documentation contents page