Hello Guest

Author Topic: Error when using keys  (Read 4005 times)

0 Members and 1 Guest are viewing this topic.

Frankity

  • Member
  • Posts: 6
    • View Profile
Error when using keys
« on: November 12, 2015, 08:09:55 AM »
hi, i was trying to follow the Otter 2D Top-Down Adventure Tutorial, but i can't keep working on it due this error, the key assignation in the tutorial are different in relation with the actual version of Otter.

the Otter 2d top... code look like this:

Code: [Select]
Global.PlayerSession.Controller.Up.AddKey(Key.Up);
and the code for the actual version of Otter, my code in this case is this:

Code: [Select]
Global.PlayerSession.Controller.AddButton("Right", "Left");
the problem is when i run the game this exception appear:



is there a way to handle or fix it?

Frankity

  • Member
  • Posts: 6
    • View Profile
Re: Error when using keys
« Reply #1 on: November 12, 2015, 09:23:18 AM »
hi again,

i fixed the thing using some code:

Code: [Select]
var axis = AddComponent(Axis.CreateWASD());
            var movement = AddComponent(new BasicMovement(400, 400, 10));
            movement.Axis = axis;

and this:

Code: [Select]
if (Input.KeyDown(Key.A))
            {
                X -= moveSpeed;
                sprite.Play("walkLeft");
                sprite.FlippedX = true;
                direction = Global.DIR_LEFT;
            }

thanks anyway :D

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Error when using keys
« Reply #2 on: November 12, 2015, 09:28:13 AM »
Are you creating a button for "Left" before trying to use it?  It appears as if the button is null when trying to check it (the null reference exception)

Frankity

  • Member
  • Posts: 6
    • View Profile
Re: Error when using keys
« Reply #3 on: November 12, 2015, 09:31:29 AM »
Are you creating a button for "Left" before trying to use it?  It appears as if the button is null when trying to check it (the null reference exception)

yes, i was confused with this but after reading the doc, i found a nice and clean solution :D, thanks