question

Unnamed Studio avatar image
Unnamed Studio asked

Namespace Dictionary could not be found

Hey guys, I spent a few hours trying different solutions and trying other peoples solutions with no avail.

Could anyone help me get this to work? I'm trying to get

UpdateUserData

to add/update to a user but I get this error:

Assets/PlayFabManager.cs(73,36): error CS0246: The type or namespace name `Dictionary' could not be found. Are you missing a using directive or an assembly reference?

My code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;

public class PlayFabManager : MonoBehaviour {

    public string PlayFabId;

    void Login(string titleId)
    {
        LoginWithCustomIDRequest request = new LoginWithCustomIDRequest()
        {
            TitleId = titleId,
            CreateAccount = true,
            CustomId = SystemInfo.deviceUniqueIdentifier
        };

        PlayFabClientAPI.LoginWithCustomID(request, (result) => {
            PlayFabId = result.PlayFabId;
            Debug.Log("Got PlayFabID: " + PlayFabId);

            if(result.NewlyCreated)
            {
                Debug.Log("(new account)");
            }
            else
            {
                Debug.Log("(existing account)");
                SetUserData();
                GetUserData();
            }
        },
        (error) => {
            Debug.Log("Error logging in player with custom ID:");
            Debug.Log(error.ErrorMessage);
        });
    }

    void GetUserData()
    {
        GetUserDataRequest request = new GetUserDataRequest()
        {
            PlayFabId = PlayFabId,
            Keys = null
        };

        PlayFabClientAPI.GetUserData(request,(result) => {
            Debug.Log("Got user data:");
            if ((result.Data == null) || (result.Data.Count == 0))
            {
                Debug.Log("No user data available");
            }
            else
            {
                Debug.Log (result.Data["age"].Value);
                foreach (var item in result.Data)
                {
                    Debug.Log("    " + item.Key + " == " + item.Value.Value);
                }
            }
        }, (error) => {
            Debug.Log("Got error retrieving user data:");
            Debug.Log(error.ErrorMessage);
        });
    }

    void SetUserData()
    {
        UpdateUserDataRequest request = new UpdateUserDataRequest()
        {
            Data = new Dictionary(){
                {"Ancestor", "Arthur"},
                {"Successor", "Fred"}
            }
        };

        PlayFabClientAPI.UpdateUserData(request, (result) =>
                                        {
            Debug.Log("Successfully updated user data");
        }, (error) =>
        {
            Debug.Log("Got error setting user data Ancestor to Arthur");
            Debug.Log(error.ErrorDetails);
        });
    }

    void Awake(){
        PlayFabSettings.TitleId = "HIDDEN"; //your title id goes here.
    }

    // Use this for initialization
    void Start () {
        Login ("HIDDEN");

    }

    // Update is called once per frame
    void Update () {

    }
}

Thank you!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Unnamed Studio avatar image
Unnamed Studio answered

I did it a different way instead of using Dictionary. I replaced

    {
        Data = new Dictionary(){
            {"Ancestor", "Arthur"},
            {"Successor", "Fred"}
        }
    };

with

    request.Data = new Dictionary<string, string>();
    request.Data.Add("It's over", "9000!!!");
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.