| None. |
|
Starts hosting a network game called "Blitz3D" on this machine. In classic Blitz3D this command opened a DirectPlay setup dialog, where the player chose whether to host or join a game. Blitz3D+ shows no dialog: StartNetGame does exactly what HostNetGame("Blitz3D") does and returns straight away. Other machines join with JoinNetGame("Blitz3D",address), giving this machine's IP address - the game name has to match. If your players should choose between hosting and joining, put that choice in your own menu and call HostNetGame or JoinNetGame. The return value tells you how it went: 0 : no game could be started, for example because another program is using the network port 2 : a new game was created and this machine is the host It never returns 1, the "joined a game" result, which only JoinNetGame gives. A session must be running before any of the other player-message commands work - create at least one player with CreateNetPlayer, then talk with SendNetMsg and RecvNetMsg. Only one session can be active at a time; starting another without StopNetGame first raises a runtime error. The current Windows runtime implements this classic player-message API with Winsock. For shared scenes across desktop, mobile and web, see the Extended Shared World multiplayer guide. Classic NetGame and Shared World sessions cannot run together. See also: HostNetGame, JoinNetGame, StopNetGame, CreateNetPlayer. |
; StartNetGame Example
; --------------------
; StartNetGame starts hosting a game called "Blitz3D" straight away.
; It returns 2 when this machine is hosting, or 0 if it could not start.
status=StartNetGame()
If status=2 Then
Print "StartNetGame returned 2 - now hosting 'Blitz3D'"
; A player must exist before messages can be received
host_player=CreateNetPlayer("Host")
Print "Created player '"+NetPlayerName$(host_player)+"'"
; Listen for guests - message type 100 means a player joined
Print ""
Print "Listening 8 seconds for joiners..."
Print "(a second copy can join with JoinNetGame, using the name Blitz3D)"
start=MilliSecs()
While MilliSecs()-start<8000
If RecvNetMsg() Then
If NetMsgType()=100 Then Print NetPlayerName$(NetMsgFrom())+" joined the game!"
If NetMsgType()=101 Then Print "A player left the game"
EndIf
Delay 10
Wend
; Always end the session when done
StopNetGame
Print "Game stopped"
Else
Print "StartNetGame returned "+status+" - hosting failed"
Print "(another program may be using the network port)"
EndIf
Print ""
Print "Press any key to close the example"
WaitKey
End