It is currently 7:35 pm 09/07/10


Post a new topicPost a reply Page 1 of 1   [ 5 posts ]
Author Message
 Post subject: Player purchasing game
PostPosted: 5:56 pm 07/27/10 
FRB Scholar
FRB Scholar

Joined: 2:00 pm 10/29/09
Posts: 148
As per my conversation with Josh on the chat room, here is some easy cheesy purchasing code for xbox
\

here is the method for checking that they can purchase it
Code:
public bool CanBuyGame(PlayerIndex player)
        {
            SignedInGamer gamer = Gamer.SignedInGamers[player];

            if (gamer == null)
                return false;

            if (!gamer.IsSignedInToLive)
                return false;

            return gamer.Privileges.AllowPurchaseContent;
        }


and here is the code I use to call it
Code:
if (Guide.IsTrialMode)
{
     if(this.gamePad.CanBuyGame(StaticVariables.pIndex))
     {
          try
          {
           Guide.ShowMarketplace(StaticVariables.pIndex);
           }
            catch
            {
             }
      }
}


Top
 Profile E-mail  
 
 Post subject: Re: Player purchasing game
PostPosted: 2:43 pm 07/28/10 
FRB Specialist
FRB Specialist

Joined: 12:11 pm 04/04/09
Posts: 441
Location: Massachusetts
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.

_________________
GouldComputing
- The Challenge Awaits -


Top
 Profile  
 
 Post subject: Re: Player purchasing game
PostPosted: 4:21 pm 07/28/10 
FRB Scholar
FRB Scholar

Joined: 2:00 pm 10/29/09
Posts: 148
Actually the code above gets the gamer that is signed in to the player index, which is set from which controller initiated the purchase

Code:
SignedInGamer gamer = Gamer.SignedInGamers[player];


and then if it returns null it returns false meaning no one is signed in... then proceeds to go through the other stuff.

I stole/borrowed it from Nick Gravelyn and havent had a problem with it yet... although that doesnt mean there couldnt be a problem ever


Top
 Profile E-mail  
 
 Post subject: Re: Player purchasing game
PostPosted: 4:23 pm 07/28/10 
FRB Scholar
FRB Scholar

Joined: 2:00 pm 10/29/09
Posts: 148
And while I havent tried your code yet Gould there might be an EC problem with it.

You are looping through all of the player indexes looking for the first signed in gamer. When you find it you pass that index to allow the purchasing. But If my controller one is signed in to live but I am playing with controller two, the first controller would receive the purchase dialog and could cause a fail in peer review.


Top
 Profile E-mail  
 
 Post subject: Re: Player purchasing game
PostPosted: 4:35 pm 07/29/10 
FRB Specialist
FRB Specialist

Joined: 12:11 pm 04/04/09
Posts: 441
Location: Massachusetts
Yeah, I have that fixed actually. In my code, "index" is actually passed into the function and is the controller index that pushed the button. Because it matches that first when it loops through all the controllers, this addresses the EC problem.
However, yours is much more elegant. I thought I remembered seeing it from Nick. Maybe when I get a chance I will try it with many controllers and see if it fails in some form.

_________________
GouldComputing
- The Challenge Awaits -


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 5 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
twilightBB Style by Daniel St. Jules of Gamexe.net