Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by TheJamiryu · Jan 27, 2019 at 11:38 PM · dataentities

Help about Entity

I did as described from https://api.playfab.com/docs/tutorials/entities/getting-started-entities but still I'm getting error(OnPlayFabError).

using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
using PlayFab.AuthenticationModels;
using PlayFab.DataModels;
using EntityKey = PlayFab.DataModels.EntityKey;


public class KongregateHandler : MonoBehaviour


    public string entityId;
    public string entityType;


PlayFabClientAPI.LoginWithKongregate(new LoginWithKongregateRequest
        {
            KongregateId = kongregateId,
            AuthTicket = authTicket,
            CreateAccount = true
        }, OnLoggedIn, OnFailed);
        PlayFabAuthenticationAPI.GetEntityToken(new GetEntityTokenRequest(),
            (entityResult) =>
        {
             var entityId = entityResult.Entity.Id;
             var entityType = entityResult.Entity.Type;
        }, OnPlayFabError);


private void OnPlayFabError(PlayFabError obj)
    {
        Debug.Log("Entity Error");
    }
private void OnLoggedInn(EntityTokenResponse obj)
    {
        entityId = obj.EntityToken;
    }

Can you guys also check SetObjects and GetObjects looks okey ?

public void EntitySave()
    {
        var data = new Dictionary<string, object>()
    {
          {"sHp", karakter.karakterStartHp},
          {"HpMulti", karakter.healthMultiply},
          {"Dmg", karakter.damage},
          {"DmgMulti", karakter.damageMultiply},
          {"AliveB", karakter.EnemyAliveBonus},
          {"Rng", karakter.range},
          {"Rate", karakter.fireRate},
          {"CritC", karakter.critChance},
          {"CritM", karakter.critMultiply},
          {"Steal", karakter.lifeSteal},
          {"Penet", karakter.penetration},
          {"Redu", karakter.damageReduction},
          {"PoiC", karakter.poisonChance},
          {"PoiMulti", karakter.poisonDamageMultiply},
          {"LastS", karakter.lastStandDamageMultiply},
          {"LightC", karakter.lightChance},
          {"LightMulti", karakter.lightDamageMultiply},
          {"Hp", karakter.karakterHp}
    };
          var dataList = new List<SetObject>()
    {
          new SetObject()
    {
            ObjectName = "PlayerData",
            DataObject = data
    },


    };
        PlayFabDataAPI.SetObjects(new SetObjectsRequest()
        {
            Entity = new EntityKey { Id = entityId, Type = "character"},
            Objects = dataList,
        }, (setResult) => {
            Debug.Log(setResult.ProfileVersion);
        }, OnPlayFabError);
    }
    public void EntityLoad()
    {
        var getRequest = new GetObjectsRequest { Entity = new EntityKey { Id = entityId, Type = "character" } };
        PlayFabDataAPI.GetObjects(getRequest,
            result => { var objs = result.Objects; },
            OnPlayFabError
        );
    }

Thank you.

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Hernando · Jan 28, 2019 at 07:11 AM

There are several problems in your code:

  1. You can get EntityID and EntityType from LoginWithKongregate result, so you don't need to call GetEntityToken.
  2. The method "OnLoggedInn" seems like having a spelling mistake, and the parameter is not correct. (Line 37)

In summary, you can modify the method LoginWithKongregate to get the entityId and entityType by referring to the following code.

public string entityId;
public string entityType;

PlayFabClientAPI.LoginWithKongregate(new LoginWithKongregateRequest
{            

	KongregateId = kongregateId,

	AuthTicket = authTicket,

	CreateAccount = true

},OnLoggedIn,
OnPlayFabError);


private void OnLoggedIn(LoginResult result)    {

	entityId = result.EntityToken.Entity.Id;         
	entityType = result.EntityToken.Entity.Type;
}

As for SetObjects and GetObjects, at line 36&44, you should use the field "entityType" as replace to hardcode string.

Please refer to this code:

var getRequest = new GetObjectsRequest { Entity = new EntityKey { Id = entityId, Type = entityType } };
Comment
TheJamiryu

People who like this

1 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by TheJamiryu · Jan 31, 2019 at 09:03 PM

First of all, thank you so much for your help. Everything is working right now. Only thing left is get saved values. I have set up 3 entity objects for my game data. All key/value pairs are correct when I check it on Game Manager. I believe GetObjectsRequest is not enough by itself. How should I get these saved pairs.

public void EntitySave()
    {
        var data = new Dictionary<string, object>()
    {
          {"L", levelup.level},

    };
          var dataList = new List<SetObject>()
    {
          new SetObject()
    {
            ObjectName = "PlayerData",
            DataObject = data
    },


    };
        PlayFabDataAPI.SetObjects(new SetObjectsRequest()
        {
            Entity = new EntityKey { Id = entityId, Type = entityType },
            Objects = dataList,
        }, (setResult) => {
            Debug.Log(setResult.ProfileVersion);
        }, OnPlayFabError);

public void EntitySave2()
    {
        var data2 = new Dictionary<string, object>()
    {

            {"S1", skilltree.survivorSkill1Level},
            
        };
        var dataList = new List<SetObject>()
    {
          new SetObject()
    {
            ObjectName = "PlayerData2",
            DataObject = data2
    },


    };
        PlayFabDataAPI.SetObjects(new SetObjectsRequest()
        {
            Entity = new EntityKey { Id = entityId, Type = entityType },
            Objects = dataList,
        }, (setResult) => {
            Debug.Log(setResult.ProfileVersion);
        }, OnPlayFabError);
    }

public void EntitySave3()
    {
        var data3 = new Dictionary<string, object>()
    {
            
            {"16", forge.forge16Level},
            
        };
        var dataList = new List<SetObject>()
    {
          new SetObject()
    {
            ObjectName = "PlayerData3",
            DataObject = data3
    },


    };
        PlayFabDataAPI.SetObjects(new SetObjectsRequest()
        {
            Entity = new EntityKey { Id = entityId, Type = entityType },
            Objects = dataList,
        }, (setResult) => {
            Debug.Log(setResult.ProfileVersion);
        }, OnPlayFabError);
    }


Thank you very much.

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hernando · Feb 01, 2019 at 02:59 AM 0
Share

Below is a simple code that demonstrates how to get a value from Object "PlayerData" after calling the GetOjects API.

        PlayFabDataAPI.GetObjects(getRequest,
        result => {
            JsonObject jsonResult = (JsonObject)result.Objects["PlayerData"].DataObject;
            object karakterStartHp;
            if (jsonResult.TryGetValue("sHp", out karakterStartHp))
            {
            	Debug.Log(karakterStartHp.ToString());
            }
        },
        OnPlayFabError)
avatar image

Answer by garrygaber · Sep 09, 2019 at 07:49 PM

Hi Hernando -

What are you using to get the type JsonObject in the above code?

Kindest Regards,
Garry

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by garrygaber · Sep 10, 2019 at 01:29 AM

After some research, I found the answer: just add using PlayFab.Json; to the top of the script.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    Pro Tier limits and the entity data 3 Answers

    Client_focus_change 1 Answer

    Size of entity data (how much can 500 bytes fit?) 2 Answers

    Where to store Minecraft-like world data? 1 Answer

    How to convert Entity in group models to profiles models? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges