CreateNetPlayer ( name$ )
Parameters
| name$ - name for the new player |
Description
|
Creates a local player in the current network game. Returns the player's id - the number you pass to SendNetMsg as the sender and get back from NetMsgFrom on other machines - or 0 on failure. Every machine in the session is told about the new arrival with a join message (type 100). You must create at least one player before you can send or receive messages, even if that player is only there to lurk. A single machine may create several players (useful for a local splitscreen pair in an online game). Names are just labels - they do not have to be unique - and NetPlayerName$ looks them up from an id. Calling this with no game running raises a runtime error - host or join first. See also: DeleteNetPlayer, NetPlayerName, NetPlayerLocal, SendNetMsg. |
Example
; CreateNetPlayer Example ; ----------------------- ; Host a game directly (2 = success) status=HostNetGame("demo game") If status=2 Then Print "Hosting 'demo game'" Print "" ; CreateNetPlayer adds a local player and returns a player id ; (0 = failed). At least one player must exist before messages ; can be sent or received, and every machine is told about it. alice=CreateNetPlayer("Alice") bob=CreateNetPlayer("Bob") If alice=0 Or bob=0 Then Print "The players could not be created" Else Print "Created '"+NetPlayerName$(alice)+"' with id "+alice Print "Created '"+NetPlayerName$(bob)+"' with id "+bob Print "" Print "Message commands use these ids to say who is talking" EndIf StopNetGame Print "" Print "Game stopped" Else Print "HostNetGame returned "+status+" - could not host a game" Print "(network play may be unavailable on this machine)" EndIf Print "" Print "Press any key to close the example" WaitKey End
Index