There is a potential problem with that logic that I ran into with Avatars Skate and got knocked off of peer review.
Where player = PlayerIndex player, the below line of code:
Code:
SignedInGamer gamer = Gamer.SignedInGamers[player];
may not be correct. Here is an excerpt from MSDN:
Quote:
Represents a collection of all gamers on the local system. The collection is sorted by the gamer index, skipping non-existent gamer indices. For example, if gamers 1 and 3 are signed in, the collection contains two instances of SignedInGamer, with gamer 1 first in the collection.
So, if I have controller 1 and 3 signed in, and I try to buy with 3, the game will crash. At least it did when I was doing my tests. Below is what I used for calling the marketplace (after some help from the CC forums):
Code:
PlayerIndex? live = null;
for (int s = 0; s < Gamer.SignedInGamers.Count; s++)
{
if (Gamer.SignedInGamers[s].PlayerIndex == (PlayerIndex)index)
{
if (Gamer.SignedInGamers[s].IsSignedInToLive)
live = (PlayerIndex)index;
}
}
try
{
if (live == null)
{
//still none, so notify the player
Guide.BeginShowMessageBox("Cannot open Marketplace", "To purchase the game, you must sign in a gamer with an Xbox Live account.",
new List<string> { "OK" }, 0, MessageBoxIcon.Alert, null, null);
}
else
Guide.ShowMarketplace((PlayerIndex)live);
}
catch { }
Although, I had not caught the AllowPurchaseContent part, so I'll add that in.