Вы находитесь на странице: 1из 3

New indicators at studio:

IS_HOST
NETWORK_TIME
networkRand(<optional>lowerBound, upperBound)
Initialization:
game.networking.connect()
In lobby:
game.networking.loadOnlineFriends(globalCallbackName)
Callback receives nothing, gets called when data was loaded successfully
game.networking.startGameWithFriends(requestId, requestMessage, friendIds)
game.networking.joinRoomFromInvitation(gameId)
Ask Lior about this one.
GameId is sent at Arg1 of the request.
game.networking.startRandomGame(maxPlayers, roomProperties)
roomProperties is a string-to-number table. Will only join games created
with same properties.
game.networking.leaveRoom()
In room:
game.networking.setIsRoomVisible(isVisible)
game.networking.amITheHost()
Returns true/false. May change after a player has left the room (should be
rechecked at that event)
game.networking.getNumberOfPlayersInRoom()
game.networking.startGame()
Causes all players to execute "GAME_STARTED" event simultaneously (after
some delay).
After that event, NETWORK_TIME and networkRand are synchronized among the
players.
Game is locked after this event (other players won't be able to join)
not yet implemented.
Event handling:
game.networkingEvents.send(eventId, args)
Sends a custom event to all players in room. Custom event are handled like
normal events (see event handling).
FW: Multiplayer
oi va 09 aiupix 2013 11:01
Multiplayer Page 1
normal events (see event handling).
eventId A number representing the type of event (see event handling)
args A string-to-string table.
game.networkingEvents.bind(eventId, func)
Registers an event handler.
eventId is either a custom event number (defined by the developer) or one
of:
game.enums.EngineEvents.DISCONNECTED (args: empty)
game.enums.EngineEvents.JOINED_ROOM (args: empty)
game.enums.EngineEvents.LEFT_ROOM (args: empty)
game.enums.EngineEvents.PLAYER_JOINED_ROOM (args: playerNumber,
playerId)
game.enums.EngineEvents.PLAYER_LEFT_ROOM (args: playerNumber)
game.enums.EngineEvents.GAME_STARTED (args: empty)
game.enums.EngineEvents.CONNECTED (args: empty)
For custom events, eventId and the received args are whatever were passed
to sendEvent.
playerNumber unique across the game room
playerId globally unique (Facebook ID, or some random ID if that player
is not connected to Facebook)
game.networkingEvents.unbind(eventId)
game.networkingEvents.unbindAll()
Example game script:
-- On startup:
FIRE_MISSILE = 1
game.networkingEvents.bind(game.enums.EngineEvents.JOINED_ROOM,
function(args)
trace("In room")
if game.networking.amITheHost() then trace("I'm the host") end
end)
game.networkingEvents.bind(game.enums.EngineEvents.PLAYER_JOINED_ROOM,
function(args)
trace("Player "..args.playerNumber.." joined")
game.networkingEvents.send(FIRE_MISSILE, {target=args.playerNumber})
end)
game.networkingEvents.bind(game.enums.EngineEvents.PLAYER_LEFT_ROOM,
function(args)
trace("Player "..args.playerNumber.." joined")
if game.networking.amITheHost() then trace("Now I'm the host") end
end)
game.networkingEvents.bind(FIRE_MISSILE, function(args)
trace("A missile was fired on "..args.target)
end)
-- On "start game" button
game.networking.connect()
game.networking.startRandomGame(10, {level=myLevel})
Multiplayer Page 2
Multiplayer Page 3

Вам также может понравиться