Version 2.0!
Features
Tutorials
Files
Glossary
Projects
Contact
Links
Message Board
Extras
LuckyCam
Old News
Sign Guestbook
View Guestbook
VB Horoscope
VB Photo Album
.
ATTENTION READERS! Lucky's VB Gaming Site is no longer active. For updated game programming information and tutorials, please visit The Game Programming Wiki!

Commencing Gameplay

When a session has been started, we need to be able to monitor how many people have joined that session. In other words, we need to enumerate the players.

Dim i As Integer
Dim intPlayersWaiting As Integer
Dim objEnumPlayers As DirectPlayEnumPlayers
  
    Set objEnumPlayers = dp.GetDPEnumPlayers("", 0)
    
    intPlayersWaiting = objEnumPlayers.GetCount
      
    For i = 1 To intPlayersWaiting
        LstBox.AddItem objEnumPlayers.GetShortName(i)
    Next

This code will list the short names of every player connected to the current session (again, "LstBox" refers to a valid listbox object). The user (usually the host) can use this information to decide when to commence the game. For example, a game may allow 4 players to join, but the host could start the game when there were only two or three if desired. Once the game starts, the host should disable the "join" ability to keep new players from joining the session late.

Dim objSessionData As DirectPlaySessionData

    Set objSessionData = dp.CreateSessionData
    dp.GetSessionDesc objSessionData
    objSessionData.SetFlags objSessionData.GetFlags Or DPSESSION_JOINDISABLED
    dp.SetSessionDesc objSessionData

Fill a DirectPlaySessionData object with session data. Use the current flags in conjunction with the DPSESSION_JOINDISABLED flag to disable joining. Once the flags are defined, set the session data using the same object and the DirectPlay4.SetSessionDesc method.

You know how it feels when you have to go to the bathroom, and you're waiting in line for your turn to go, and you know you're almost there, but you have to hold it just a LITTLE BIT LONGER? Read the In-Game Messaging tutorial and let it all out! (click here to download this tutorial's source code)