Someone gifted MetalSlayer69 supporter status!
We need you on the team, too.
Support Newgrounds and get tons of perks for just $2.99!
Create a Free Account and then..
Become a Supporter!At 4/24/20 05:24 PM, mayorDump wrote: How do you check if a medal has already been unlocked? I imagine it has to do with Medal.getList, but I'm not sure how to access the data (I'm shockingly unfamiliar with how lists work...)
You can do something like this (assuming ngioCore is an initialised core component):
// Get the medal list var medalList = new components.Medal.getList(); medalList.callWith(ngioCore, OnGetMedalList);
Which calls the OnGetMedalList method when it's done.
using System.Linq; [SerializeField] int id = 0; // medal ID of the medal you want to unlock void OnGetMedalList(getList getList) { List<medal> medals = getList.medals.Cast<medal>().ToList(); // cast the result into a list of medals (which should work if there are no other problems) medal current = medals.FirstOrDefault(m => m.id == id); // first medal with our ID if (current == null) { //! Wrong ID or bad cast if (medals.Count >= 1 && id != 0) { // Good cast, bad ID Debug.LogWarning($"Trying to unlock a non-existent medal with ID: <b>{id}</b>.\nCheck your <i>Project Settings</i> on Newgrounds; and make sure you created a matching Medal asset in Unity."); } return; } if (!current.unlocked) { var medalUnlock = new components.Medal.unlock {id = current.id}; try { medalUnlock.callWith(ngioCore, OnMedalUnlocked); } catch (InvalidCastException) { //! Failed to unlock (see enable network data log) Debug.LogWarning("Failed to unlock the medal. Try enabling the network data option of 'Core' prefab to see more details."); } } }
If you just want the list, the first line is enough. You can then pick a medal from the list (e.g. the one with ID we want here) and check if it's unlocked "yourMedal.unlocked". Make sure it's not null or wrong (if you supply a bad ID, for example).
I don't think it's a big issue if you unlock a medal twice, but if you're showing a medal popup, for example, you don't want to show it twice to the same user, at least not during the same game session.
Also, the above code doesn't check for people who aren't logged in / unregistered users; and for those the unlocked property will always be false (I think), so you might want to keep a list of medals unlocked during the current game session somewhere to avoid spamming medal popups – or just don't show popups to people who aren't logged in.
At 4/24/20 05:24 PM, mayorDump wrote: How do you check if a medal has already been unlocked? I imagine it has to do with Medal.getList, but I'm not sure how to access the data (I'm shockingly unfamiliar with how lists work...)
You can do something like this (assuming ngioCore is an initialised core component):
// Get the medal list var medalList = new components.Medal.getList(); medalList.callWith(ngioCore, OnGetMedalList);
Which calls the OnGetMedalList method when it's done.
using System.Linq; [SerializeField] int id = 0; // medal ID of the medal you want to unlock void OnGetMedalList(getList getList) { List<medal> medals = getList.medals.Cast<medal>().ToList(); // cast the result into a list of medals medal current = medals.FirstOrDefault(m => m.id == id); // first medal with our ID if (current == null) { //! Wrong ID or bad cast if (medals.Count >= 1 && id != 0) { // Good cast, bad ID Debug.LogWarning($"Trying to unlock a non-existent medal with ID: <b>{id}</b>.\nCheck your <i>Project Settings</i> on Newgrounds; and make sure you created a matching Medal asset in Unity."); } return; } if (!current.unlocked) { var medalUnlock = new components.Medal.unlock {id = current.id}; try { medalUnlock.callWith(ngioCore, OnMedalUnlocked); } catch (InvalidCastException) { //! Failed to unlock (see enable network data log) Debug.LogWarning("Failed to unlock the medal. Try enabling the network data option of 'Core' prefab to see more details."); } } }
If you just want the list, the first line is enough. You can then pick a medal from the list (e.g. the one with ID we want here) and check if it's unlocked "yourMedal.unlocked". Make sure it's not null or wrong (if you supply a bad ID, for example). If you're getting InvalidCastException (which I catch in the code above), that seems to mean it couldn't unlock the medal / get the list; presumably because the core component wasn't initialised properly (you can check the exact reason by enabling network data output: ngioCore.output_network_data = true).
I don't think it's a big issue if you unlock a medal twice (it won't fail or cause an error), but if you're showing a medal popup, for example, you don't want to show it twice to the same user, at least not during the same game session.
Also, the above code doesn't check for people who aren't logged in / unregistered users; and for those the unlocked property will always be false (I think), so you might want to keep a list of medals unlocked during the current game session somewhere to avoid spamming medal popups – or just don't show popups to people who aren't logged in.
At 4/24/20 05:24 PM, mayorDump wrote: How do you check if a medal has already been unlocked? I imagine it has to do with Medal.getList, but I'm not sure how to access the data (I'm shockingly unfamiliar with how lists work...)
You can do something like this (assuming ngioCore is an initialised core component):
// Get the medal list var medalList = new components.Medal.getList(); medalList.callWith(ngioCore, OnGetMedalList);
Which calls the OnGetMedalList method when it's done.
using System.Linq; [SerializeField] int id = 0; // medal ID of the medal you want to unlock void OnGetMedalList(getList getList) { List<medal> medals = getList.medals.Cast<medal>().ToList(); // cast the result into a list of medals (which should work if there are no other problems) medal current = medals.FirstOrDefault(m => m.id == id); // first medal with our ID if (current == null) { //! Wrong ID or bad cast if (medals.Count >= 1 && id != 0) { // Good cast, bad ID Debug.LogWarning($"Trying to unlock a non-existent medal with ID: <b>{id}</b>.\nCheck your <i>Project Settings</i> on Newgrounds; and make sure you created a matching Medal asset in Unity."); } return; } if (!current.unlocked) { var medalUnlock = new components.Medal.unlock {id = current.id}; try { medalUnlock.callWith(ngioCore, OnMedalUnlocked); } catch (InvalidCastException) { //! Failed to unlock (see enable network data log) Debug.LogWarning("Failed to unlock the medal. Try enabling the network data option of 'Core' prefab to see more details."); } } }
If you just want the list, the first line is enough. You can then pick a medal from the list (e.g. the one with ID we want here) and check if it's unlocked "yourMedal.unlocked". Make sure it's not null or wrong (if you supply a bad ID, for example).
I don't think it's a big issue if you unlock a medal twice, but if you're showing a medal popup, for example, you don't want to show it twice to the same user, at least not during the same game session.
Also, the above code doesn't check for people who aren't logged in / unregistered users; and for those the unlocked property will always be false (I think), so you might want to keep a list of medals unlocked during the current game session somewhere to avoid spamming medal popups – or just don't show popups to people who aren't logged in.
At 4/24/20 05:24 PM, mayorDump wrote: How do you check if a medal has already been unlocked? I imagine it has to do with Medal.getList, but I'm not sure how to access the data (I'm shockingly unfamiliar with how lists work...)
You can do something like this (assuming ngioCore is an initialised core component):
// Get the medal list var medalList = new components.Medal.getList(); medalList.callWith(ngioCore, OnGetMedalList);
Which calls the OnGetMedalList method when it's done.
using System.Linq; [SerializeField] int id = 0; // medal ID of the medal you want to unlock void OnGetMedalList(getList getList) { List<medal> medals = getList.medals.Cast<medal>().ToList(); // cast the result into a list of medals (which should work if there are no other problems) medal current = medals.FirstOrDefault(m => m.id == id); // first medal with our ID if (current == null) { //! Wrong ID or bad cast if (medals.Count >= 1 && id != 0) { // Good cast, bad ID Debug.LogWarning($"Trying to unlock a non-existent medal with ID: <b>{id}</b>.\nCheck your <i>Project Settings</i> on Newgrounds; and make sure you created a matching Medal asset in Unity."); } return; } if (!current.unlocked) { var medalUnlock = new components.Medal.unlock {id = current.id}; try { medalUnlock.callWith(ngioCore, OnMedalUnlocked); } catch (InvalidCastException) { //! Failed to unlock (see enable network data log) Debug.LogWarning("Failed to unlock the medal. Try enabling the network data option of 'Core' prefab to see more details."); } } }
If you just want the list, the first line is enough. You can then pick a medal from the list (e.g. the one with ID we want here) and check if it's unlocked "yourMedal.unlocked". Make sure it's not null or wrong (if you supply a bad ID, for example).
I don't think it's a big issue if you unlock a medal twice, but if you're showing a medal popup, for example, you don't want to show it twice to the same user, at least not during the same game session.
Also, the above code doesn't check for people who aren't logged in / unregistered users; and for those the unlocked property will always be false (I think), so you might want to keep a list of medals unlocked during the current game session somewhere to avoid spamming medal popups – or just don't show popups to people who aren't logged in.