[SOLVED] Cant Read Keyboard of Undefined

Im Not Sure why I am getting this error
can i have some pointers on how to fix this, and how to prevent this for later

@Thebosser_24 Is this the same project? Could you post a link so someone can have a look?

1 Like

https://playcanvas.com/editor/scene/1548413

this is it
i just wanna know what i can do to fix this ussue

@Thebosser_24 This is the line that needs fixed. I think this is a place that I pointed out in a previous post. From line 163 to 171. It does not look formatted properly as well as maybe inside a prototyped function. If you comment these lines out, does it work?

if (app.keyboard.isPressed(pc.KEY_R)){
this.rounds = 35;

Also it seems like your resources are over still but not sure.

I think @Tirk182 means the same, but currently line 170 to 180 is outside a function. You need to create a function for it and place the code inside that function. Apart from that, checking for a key press inside a timeout looks strange to me?

2 Likes

@Thebosser_24 This is the code that @Albertos and I are referring to.

image

All functions that we prototype have the following format.

Movement.prototype.doThisFunction = function () {

// Do operation

};

So have your setTimeout outside of a function like this will cause errors. You could just comment these lines from 170 to 180 and give your script a try. Remember to save afterwards.

2 Likes

so i have included the script into the update function, and no errors occur, but it wont let me look around, my mouse doesnt “dissapear”

@Thebosser_24 Is it the same link to the same project above? If it is I still see this in Main.js

 // RELOAD AND AMMO STARTS HERE  \/  //
   
   setTimeout(function() {
// Reload

    var app = this.app;

   if (app.keyboard.isPressed(pc.KEY_R)){
       this.rounds = 35;
}
  }
   

.bind(this), 3000);
 // reload gun magazine
1 Like

@Tirk182 Yes the project is the same, and i tried to comment the part of the script out, and a whole number of errors happened, so i found out what the issue is and now the error is gone, but now my mouse wont work, it wont read that my mouse clicked. and im sure it broke during the start of getting everything in the right place, and what i did to fix the Keyboard issue did not break the mouse.

what do you mean about the keypress and the timeout?

@Thebosser_24 Lines 169 thu 180 are still in the code. I don’t know if this is causing your issue with your keyboard or movement. Also, I do still see that your resources are still over. Maybe this is from other projects you have in your projects folder or not.

1 Like

my movement is fine now, i get no errors, my problem is the fact that PointerLock is not working.
i am aware 169-180 are still in code

Code that’s not correct can break other code too. Please also check line 94 (to 98) and line 102 (to 106), shouldn’t this be statements?

2 Likes

@Thebosser_24 OK so I found the major problem. In the top of your script I don’t know why you have changed this assignment.

var Movement = pc.createScript('Main.js');

First you should not have the .js inside the createScript() also there are naming conventions that need to be paid attention to. Here is the way it should look>

var Movement = pc.createScript('movement');

Next you MUST>>>>>>Rename your Main.js to Movement.js

There are numerous spots that can cause more problems as pointed out by @Albertos and I. They must me fixed. Like Albertos has pointed out, issues in code have a kind of ripple effect. They could prevent other parts of the code to execute properly and make other pieces of code in the chain not work. This Playcanvas document may help explain this.

https://developer.playcanvas.com/en/user-manual/scripting/anatomy/

1 Like

okay, @Tirk182 i fixed the script name
and @Albertos what statements?

@Thebosser_24 I see that you have changed the name of the script and made the adjustments inside of the script itself. Now go into the player and delete the movement script and then re add it and make sure to add the camera. When debugging I don’t see your script loading. This is possible it has old references.

I must ask one more time for you to comment out lines 169 to 180.

Another thing I noticed is that you have now moved everything into something called Folder of Folders. This may have broken the links to the scripts. Please re add each used in your project.

1 Like

Not sure if this can be the reason of the warnings to honest. It looks like the name of the scripts are changed.

2 Likes

Yes I see now that Bullet is ARBullet in the editor. So it is looking for Bullet except that it is now ARBullet

1 Like

I fixed ARBullet to just Bullet, I have Deleted the script and added it to the capsule, i have commented out the lines. how did you get the white debug thing, that looks super helpful

welp, i just deleted everything, so :person_shrugging: