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 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access the information with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list with regexes or preferably a HTML parser.
I don't know how to do it in HaxeFlixel if you're using it, but I suppose you could use a similar approach.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access the information with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list with regexes or preferably a HTML parser.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access the information with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list.
I don't know how to do it in HaxeFlixel if you're using it, but I suppose you could use a similar approach.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access the information with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list with regexes or preferably a HTML parser.
I don't know how to do it in HaxeFlixel if you're using it, but I suppose you could use a similar approach.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access the information with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list.
I don't know how to do it in HaxeFlixel if you're using it, but I suppose you could use a similar approach.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access the information with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list.
I don't know how to do it in HaxeFlixel if you're using it, but I suppose you could use a similar approach.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access it with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list.
I don't know how to do it in HaxeFlixel if you're using it, but I suppose you could use a similar approach.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access the information with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list.
I don't know how to do it in HaxeFlixel if you're using it, but I suppose you could use a similar approach.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access it with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the data in any way you want. Here's the gist of what I'm personally doing (in Unity):
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
Use it like this:
url = $"https://{ngio_core.current_user.name}.newgrounds.com/"; StartCoroutine(LoadPage(url, GetUserLevel)); void GetUserLevel(string fullPageSourceCode) { // find user stats list and pull LVL + XP from it (with regexes or something) }
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access it with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the page's source code in any way you want.
Here's the gist of what I'm personally doing in Unity:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
And "textParserMethod" to find the user stats list.
I don't know how to do it in HaxeFlixel if you're using it, but I suppose you could use a similar approach.
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access it with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the data in any way you want. Here's the gist of what I'm personally doing:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
Use it like this:
url = $"https://{ngio_core.current_user.name}.newgrounds.com/"; StartCoroutine(LoadPage(url, GetUserLevel)); void GetUserLevel(string fullPageSourceCode) { // find user stats list and pull LVL + XP from it (with regexes or something) }
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access it with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the data in any way you want. Here's the gist of what I'm personally doing (in Unity):
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
Use it like this:
url = $"https://{ngio_core.current_user.name}.newgrounds.com/"; StartCoroutine(LoadPage(url, GetUserLevel)); void GetUserLevel(string fullPageSourceCode) { // find user stats list and pull LVL + XP from it (with regexes or something) }
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access it with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the data in any way you want. Here's the gist of what I'm personally doing:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://{username}.newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://{username}.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace(BaseUserpageUrl, "{username}", UserComponent.defaultName.ToLower()); NgDebug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", UserComponent.defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) NgDebug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or returns }
Use it like this:
url = $"https://{ngio_core.current_user.name}.newgrounds.com/"; StartCoroutine(LoadPage(url, GetUserLevel)); void GetUserLevel(string fullPageSourceCode) { // find user stats list and pull LVL + XP from it (with regexes or something) }
At 5/24/20 01:14 AM, voter96 wrote: I'd like to make a game where the player's newgrounds level/experience points affect their in-game power.
How do I go about getting a read-only value for the player's level?
It's a bit more complicated, because as far as I'm aware, you can't access it with the newgrounds.io alone. I'm not sure if it's the best approach, but with the username, you can create a link to the userpage, send a GET request and parse the data in any way you want. Here's the gist of what I'm personally doing:
/// <summary> /// Loads all text from an url and after it finishes downloading, calls a method to parse the text. /// </summary> /// <param name="url">Url to load text from ("https://[username].newgrounds.com/").</param> /// <param name="textParserMethod">Method to use to parse the obtained text.</param> /// <returns>All source code text.</returns> static IEnumerator LoadPage(string url, Action<string> textParserMethod) { UnityWebRequest userpage; try { userpage = UnityWebRequest.Get(url); // url = "https://voter96.newgrounds.com/" } catch (UriFormatException) { url = Regex.Replace("https://{username}.newgrounds.com/", "{username}", defaultName); Debug.LogWarningFormat("The url you are trying to load is invalid. Loading default user <color=orange>{0}</color> from:\n{1}.", defaultName, url); userpage = UnityWebRequest.Get(url); } yield return userpage.SendWebRequest(); if (userpage.isNetworkError) Debug.LogError($"<b>{userpage.error}</b>: {url}"); else textParserMethod(userpage.downloadHandler.text); // displays data on screen or saves the stats somewhere }
Use it like this:
url = $"https://{ngio_core.current_user.name}.newgrounds.com/"; StartCoroutine(LoadPage(url, GetUserLevel)); void GetUserLevel(string fullPageSourceCode) { // find user stats list and pull LVL + XP from it (with regexes or something) }