Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Hoffa25 · Jun 05, 2015 at 06:06 AM · google play gamesgooglequests

Android Google Quest reward data file. How do I wright it in C#?

Hi! I have been stuck on this for days now:/...

When a user has accomplished a Quest in Google Play Games they should get a reward. In the google play console they want me to upload a file/script that get executed when the reward should be delivered. As an example they suggest a Json string like this:

 {
     "bonusGems": 2134,
     "extraSeconds": 12
 }

more info here: https://developers.google.com/games/services/common/concepts/quests#quest_basics

That doesnt help me much.. I want to wright it in C# if possible, but how exactly should the script look like? Lets say I just want to increase the players "gems" by 10.

// Erik

Comment
Add comment · Show 5
10 |3000 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 12boulla · Oct 28, 2015 at 01:37 PM 0
Share

I have the same problem. No idea how to tackle this. Have you got it working yet?

avatar image Hoffa25 · Nov 02, 2015 at 01:34 PM 0
Share

@12boulla

No I didnt get it to work:/ Gave it a couple of hours but no luck... Please post if you solved it! //Erik

avatar image 12boulla · Nov 02, 2015 at 04:31 PM 0
Share

@Hoffa25 I submitted an answer that i used. It's waiting for moderation atm :)

avatar image Gokuofuin · Nov 02, 2015 at 06:41 PM 0
Share

I too have not been able to get this to work, not sure exactly if its simply something obvious that I am missing.... most lightly it is since no one has answered this question.

avatar image 12boulla Gokuofuin · Nov 02, 2015 at 06:49 PM 0
Share

@Gokufuin The answer is up now, hope it is some help! If you are still unsure please let me know. And btw it wasn't just you who had trouble! I spent a good few days trying to find out how to do it! It definately is not obvious from the documentation i read.

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by 12boulla · Nov 02, 2015 at 06:42 PM

Ok, after hours of searching and asking on forums, i found the answer. This is the data text file that i submitted on the developer console:

{ "Gems" : 10 }

NOTE: This script is in a notepad document and is not c#, but you can use the value of gems, or whatever you want later...

Then in Unity in a C# script, you can get the value of whatever you set in the JSON script. This is how i did it: (I assume you know how to do the script to receive a reward for the quest, but if not i will put it in anyway)

NOTE: Using JSONObject plugin from the asset store

How to get the value:

 string reward = System.Text.Encoding.UTF8.GetString(quest.Milestone.CompletionRewardData);
                     JSONObject rewardJson = new JSONObject(reward);
                     int gems = int.Parse(rewardJson.GetField("Gems").ToString());

Using it in context:

 private void ClaimMilestone(IQuestMilestone toClaim)
     {
         PlayGamesPlatform.Instance.Quests.ClaimMilestone(toClaim,
                                                          (QuestClaimMilestoneStatus status, IQuest quest, IQuestMilestone milestone) => {
             if (status == QuestClaimMilestoneStatus.Success)
             {
                 string reward = System.Text.Encoding.UTF8.GetString(quest.Milestone.CompletionRewardData);
                 JSONObject rewardJson = new JSONObject(reward);
                 int gems = int.Parse(rewardJson.GetField("Gems").ToString());
                 PlayerPrefs.SetInt("Gems", PlayerPrefs.GetInt("Gems", 0) + gems);
             }
         });
     }

I hope this helps! I know i was terribly stuck on this, but it felt great to get it solved. If you need any help just comment and i'll see if i can help you. (I hope i was clear in my answer, but if not, tell me!)

Here are some other forum questions i asked that you can look at aswell to help you:

Using variable from JSON

Another question relating

Comment
Add comment · Show 4 · Share
10 |3000 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 Gokuofuin · Nov 03, 2015 at 05:21 PM 0
Share

Something I still don't understand is why my code does not recognize the 'JSONObject' ?

Any thoughts on that guys?

avatar image 12boulla Gokuofuin · Nov 03, 2015 at 05:25 PM 1
Share

JSONObject, forgot to mention, is a plugin:

Asset Store Link

I should update my answer!

avatar image Hoffa25 · Nov 04, 2015 at 09:01 AM 0
Share

@12boulla Im working on other stuff at the moment so I cant check if boullas solution does the trick or not... But it looks promissing:)! As soon as someone confirmes that it works I will mark this question answered. //Erik

avatar image MarceloBarce · Jan 05, 2017 at 10:23 PM 0
Share

It does work very well!

However, when setting the variable in the JSON file, you have to pay attention to the Quotation marks you use in the file.

The "curvy" quotation marks won't work and will give you a error on LogCat. It must be the straight ones, like the one 12boulla used in his example.

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving/Loading Game State to/from the Cloud Google Play Services 1 Answer

Destroy Banner/Interstitial ads of AdMob? 0 Answers

Google Play Permissions and Manifest files help 1 Answer

Google Play Service - LogIn Prompt not showing up 1 Answer

Sign in/out in GPG 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges