Jump to content
  • Advertisement
  • entries
    15
  • comments
    4
  • views
    8757


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By Steffi
      Hello everyone. I have created a game using the Phaser framework. On game over the player clicks a button that takes them to an index.html page where there is a form that allows them to submit their high score. To avoid cheating, I want this score to be passed from Game.js to the form input as a read-only value. In Game.js I have a function called extractVariable that takes the players score (this.inputScore) and returns this value to itself. I have another function in Game.js called assignValue that is called by index.html when the page loads. assignValue is given extractVariable as a parameter (when it is called in index.html) that allows it to take the inputScore variable and put it into the score input on the form. Only problem is the score is undefined and I can't figure out why. When I console.log inputScore in extractVariable I get the score value, but index.html shows it as undefined. However, if I give inputScore a hard coded value inside extractVariable then it works - index.html takes the hard coded value and displays it in the form input like I want it to. Why is inputScore undefined? Any ideas as to how I can get inputScore into index.html please?
      Game.js code
      function extractVariable(inputScore) { //inputScore = 27; //if I hard code inputScore like this then it is read by index.html and passed into the form as I want it to be console.log(inputScore); //console.log shows the score correctly so we know it is receiving a value return inputScore; }; function assignValue(inputScore) { document.getElementById("playerScore").value = inputScore; }; //GAME CODE var CrystalRunner = CrystalRunner || {}; CrystalRunner.GameState = { init: function() { //...code here }, create: function() { //...code here }, update: function() { //..code here if(this.player.top >= this.game.world.height) { this.gameOver(); } }, gameOver: function(){ //..code here this.updateHighscore(); //..code here }, updateHighscore: function(){ this.highScore = +localStorage.getItem('highScore'); if(this.highScore < this.myScore){ this.highScore = this.myScore; this.inputScore = this.highScore; //this.inputScore is what I need to show in Index.html this.submitScoreButton = this.game.add.sprite(this.game.world.centerX-135, this.game.world.centerY+100, 'submitScoreButton'); this.submitScoreButton.events.onInputUp.add(function() { window.location.href = "index1.php"; //When the button is pressed the index file loads }, this); extractVariable(this.inputScore); //this.inputScore is passed into the extractVariable function at the top of the script } localStorage.setItem('highScore', this.highScore); }, }; index.html code:
      <?php require_once 'dbconnect.php'; ?> <!DOCTYPE html> <html lang="en"> <head> <title>Crystal Candy Game Login</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"/> <link href="css/style.css" rel="stylesheet"> </head> <body onload="assignValue(extractVariable())" class="bg" > <!-- here index.html calls the assignValue functon in Game.js--> <div id="preloader"> <div id="status">&nbsp;</div> </div><!--preloader--> <div class="wrapper"> <div id="main"> <form id="form-style" method="post" action="crystalhandle.php" autocomplete="off"> <div class="form-group"> <label class="header-text"><span>First Name</span></label> <input class="form-control" type="text" id="name" name="username" placeholder="Name" title="Please enter your Firstname" required=""> </div> <div class="form-group"> <label class="header-text"><span>Score</span></label> <input class="form-control" type="tel" id="playerScore" name="score" value="" readonly> <!--I need the score (inputScore) from Game.js to go into the value="" attribute here--> </div> <div class="w3ls-btn form-group"> <div class="wthreesubmitaits"> <input type="submit" name="signup" id="reg" class="button" id="next1" value="Send" style="font-family: sans-serif; font-size: 17px; font-weight: bold;" </div> </div> </form> </div> </div> <div id="bodytext"></div> <script type='text/javascript' src='js/jquery-2.2.3.min.js'></script> <script type="text/javascript" src="js/phaser.min.js"></script> <script type="text/javascript" src="js/states/Game.js"></script> <script> $(window).on('load', function() { $('#status').fadeOut(); $('#preloader').delay(350).fadeOut('slow'); $('body').delay(350).css({'overflow':'visible'}); }) </script> </body> </html>  
    • By blesseddisciple
      So I have a decent amount of JavaScript experience now and decided I was gonna lower my head and start cranking out some 2d games, partly to learn, partly to have fun. Afterall, HTML5 canvas is such an easy and enticing medium. I love the JavaScript implementation of it. But after literally struggling for a week to get basic game functionality working I have had enough of the little stupid bugs that pop up with JavaScript. Don't get me wrong, I still love the language for scripting. I'm just not going to spend 20 mins coding and 5 hours debugging just because the language is crap.
      I've decided to return to my previous endeavor, Java. I like Java a lot and the only reason I haven't pursued more in the way of game development is just for the fact that Java is limited to mobile or PC apps that may never see the light of day unless it's hosted on some obscure Java game hosting website that is populated with 2,000 half developed games that no one will ever care about. BUT, still, I enjoy hand coding and I know C# but don't feel like using Visual studio and I really don't wanna hand code C# on the .Net or whatever. I use Visual Studio for business apps (ASP.NET) but I don't wanna build a game with it.
      So, does anyone have any points to share about why moving to Java for game development is not smart? Besides the whole, "Java is slow" thing. I mean things that might make it harder in JAva to make games vs. in other languages. Please share your thoughts. 
    • By Chug Buster
      Dialogue systems suck. I hate them. I have been working on one for a project and it is just so frustrating! I finally got it just barely working, but it's the most hacked together bullshit dialogue system possible and I don't even really understand how it works. I'm just glad I can forget about it for a while, and work on the rest of the game.
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!