00:00
00:00
Newgrounds Background Image Theme

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!

Pass information to the game with variables in the url

581 Views | 1 Reply
New Topic Respond to this Topic

Good afternoon, how can I capture the information through parameters in the url using the variable "projectVars"


If I check the game, always the variable has the value "projectVars=value"


I could get it working and will describe it below, although TBH I'm not sure how practically useful it is because you have to type a string into the game's project page on NewGrounds and the projectVars will always have the value of that string.


I made a test project and on NewGrounds' project page I turned on the

Use projectVars

checkbox at the bottom, and in the text box underneath it I put

holy crap this actually worked


Then for the game I wrote this as index.html and uploaded the zip

<html>
  <head></head>
  <body>
    <script>
      let params = new URLSearchParams(document.location.search);
      let projectVars = params.get("projectVars");
      console.log("projectVars is: " + projectVars);
    </script>
  </body>
</html>


I previewed the game and checked Developer Tools - Console tab and it said

projectVars is: holy crap this actually worked

My newsfeed has random GameDev tips & tricks