session_connect(STRING* session,STRING* hostname)
Switches to a different session on another server. The first string parameter
contains the name of the new session, the second parameter gives the name, domain
or IP address of the new server. This way, level or zone changing in a multiplayer
environment can easily be performed.
Returns:
0 if the new connection could not be established, otherwise nonzero.
Parameters:
| session |
Name of the session |
| hostname |
Domain or IP Address, or NULL for a session on
the same machine |
Edition
P
Speed:
Slow
Remarks:
- This instruction can be used to switch the engine to client mode even if it wasn't
started with the -cl command line option.
- After switching from normal
to client mode, the level has to be loaded anew.
- Switching the engine to
client mode at run time has certain consequences for the script. ifdef CLIENT can
not be used - it's undefined because the engine was not started with the -cl option.
Client dependent functions or initializations must run _after_ connecting
to a session. For instance, creating a client player in the main function
won't work when the engine was not in client mode when running main().
A good place for creating the client player is after reloading the level
after connection.
Example:
if (session_connect("office","127.0.0.1"))
{
level_load("office.wmb"); // load level anew
wait(-0.5); // wait until the level state is received from the server
player_create(); // user function to place the player into the level
}
See also:
send_string,
session_open