Forum General Problem with achievements in unity3d

Any issues or discussions relating to Unity development are welcome here.

Problem with achievements in unity3d

Postby doc3000 » April 20th, 2014, 5:21 pm

Problem with Achievements on Unity3d

Postby doc3000 » Today, 3:49 pm
I don't know how declare all source, after various tentative i think i need some piece of code.
My problem is about callback, ho i must declare it?
Code i think is similar of code used in other type of connection like bigdb for example so i try to connect with playerio and after this i use client returned for make this:

client.Achievements.Refresh();
Achievement[] allAchievements = client.Achievements.MyAchievements;
var yourAchievement = client.Achievements.Get ("myac");
if (!yourAchievement.Completed)
client.Achievements.ProgressSet ("myac", 1, null, null);
else
client.Achievements.ProgressComplete ("myac", null);

i copied it for reference on web but unity say..

PlayerIOClient.PlayerIOError: AchievementsNotLoaded; Cannot access achievements before refresh is called. Please call client.Achievements.Refresh() first

please help me i don't know how i can write it...
doc3000
 
Posts: 5
Joined: March 25th, 2014, 8:31 pm

Re: Problem with achievements in unity3d

Postby Henrik » April 22nd, 2014, 12:59 am

Refresh() is asynchronous, which means that the actual refresh happens in the background. You need to use this method:

https://gamesnet.yahoo.com/documentatio ... ts#Refresh

...which means that you will need to do something like this:

Code: Select all
client.Achievements.Refresh(delegate() {
    Achievement[] allAchievements = client.Achievements.MyAchievements;
    var yourAchievement = client.Achievements.Get ("myac");
    if (!yourAchievement.Completed) {
        client.Achievements.ProgressSet ("myac", 1, null, null);
    } else {
        client.Achievements.ProgressComplete ("myac", null);
    }
},
delegate(PlayerIOError error) {
    //Error refreshing achievements...
});
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Problem with achievements in unity3d

Postby doc3000 » April 22nd, 2014, 10:57 am

many thanks..this is the code that i use to test achievements..now i can trasform for my needs :-)

client.Achievements.Refresh (delegate() {
Achievement[] allAchievements = client.Achievements.MyAchievements;
var yourAchievement = client.Achievements.Get ("3puzzle");
if (yourAchievement.Progress<yourAchievement.ProgressGoal) {
client.Achievements.ProgressAdd ("3puzzle", 1, null, null);
Debug.Log ("progress add"+yourAchievement.Progress);
} else {
client.Achievements.ProgressComplete ("5puzzle",null,null);
Debug.Log ("progress completed");
}
},
delegate(PlayerIOError error) {
//Error refreshing achievements...
});

I have just use code proposed by you, it give me only an error where say that Client.Achievements.PrgressComplete nedd 3 params not 2!!
Another question if possible...why i can't see value of progress for each achievements related to a single user?
I want say like bigdb...
doc3000
 
Posts: 5
Joined: March 25th, 2014, 8:31 pm


Return to General