is there a way to check to see if the user already has a trophy
larch13 opened this issue ยท 10 comments
I was wondering this because it keeps spamming saying I unlocked a trophy and i want to know can I check to see if I already have one then run the unlock code
yes there is, before actually unlocking the trophy, you could check if it already is unlocked:
// Call this method to unlock a specific trophy id
public static void Unlock(int id) {
Trophies.Get(id, Unlock);
}
// This method is called by the Trophies.Get call above and will only unlock a trophy if it is not already unlocked
private static void Unlock(Trophy trophy) {
if(trophy != null && !trophy.Unlocked) trophy.Unlock();
}
Okay, I'm a bit confused. I have been in locking the trophies like this
GameJolt.API.Trophies.Unlock(000000);
how could I do it the other way
Also, I used to program all the time but I stopped for like half a year so I'm not at my best right now and I was also using c++ before I stopped so I'm still in my c++ mindset, not my c# one
I can't the other method to work for the life of me
Let's say you create a helper class like so:
using GameJolt.API;
using GameJolt.API.Objects;
public static class TrophyHelper {
public static void Unlock(int id) {
Trophies.Get(id, Unlock);
}
private static void Unlock(Trophy trophy) {
if(trophy != null && !trophy.Unlocked) trophy.Unlock();
}
}
then in your script you will just call TrophyHelper.Unlock(123)
to unlock the trophy with the id 123
thanks all that worked in the unity preview but my project will not build it says that there are errors in the API
Assets/Plugins/Editor/GameJolt/SettingsEditor.cs(10,44): error CS0234: The type or namespace name Editor' does not exist in the namespace UnityEditor'. Are you missing an assembly reference?
Assets/Plugins/Editor/GameJolt/SettingsEditor.cs(11,24): error CS0115:GameJolt.Editor.SettingsEditor.OnInspectorGUI()' is marked as an override but no suitable method found to override
visual studio doesn't see them as errors and they only get in the way when building. also, I'm working on windows and building to windows 64bit
oh yeah, click on the Plugins/Editor/GameJolt/GameJoltEditor.asmdef file and make sure that only Editor
is selected for the Include Platforms
. Especially Any Platform
should not be selected.
everything seems to be working fine I just have one more problem. whenever you log in and check to remember me, there doesn't seem to be a way to log out. and so I'm stuck logged in. is there a way to log out?
well yes, you just logout: GameJoltAPI.Instance.CurrentUser.SignOut()
Since this is just a single button click, there is no special window for that, so you just create your own button/menu and call this function from your code
I can't find the SignOut() Function for some reason it won't register as an actual function I tried both GameJoltAPI.Instance.CurrentUser.SignOut() and GameJolt.API.Instance.CurrentUser.SignOut() but vs keeps complaining.
I guess you're just missing the using directive at the top:
using GameJolt.API;
then you can use GameJoltAPI.Instance.CurrentUser.SignOut();