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.