Movement question

From TDN

Original Question:

I am following through the Tutorial and I am at the part where we start learning player movement. I did everything the tutorial said but the player will not move.


Answer:

The most common error for player not moving in tutorial is this

  function playerUp()
  {
  // Set the player moving up.
  $player.setLinearVelocityY( -$10 );
  }

The -$10 should be -10

Another common error (not just with movement) for those new to programming/scripting is the following:

  When you create a "function" you do this: 
  function yourFunctionNameHere ()
  {
  
  }

the "{" signify the beginning of defining that function and the "}" defines the end of the definition... This tells the language what to use when you reference that function an important thing to remember is a function should never be in another function

So...

  function setupT2DScene()
  
  function playerUp()
  { 
  // Set the player moving up.
  $player.setLinearVelocityY( -10 ); 
  }

So, this automatically will not work. reason why is -> "function setupT2DScene()" get started... then you have put "function playerUp()" in it... You need to make sure you start setupT2DScene and end it first before you declare another function... so the format would rather be this:


  function setupT2DScene()
  {
  
  }
  
  function playerUp()
  {
  
  }

That way they are defined as separate functions.