Hello all people! I created this thread so the people can comment on here to ask the same type of question I have, why does my script give this error, and can someone help me fix it? I will go ahead with my error and script.
This is my Run script
var Run = pc.createScript('run');
// initialize code called once per entity
Run.prototype.initialize = function() {
// get the current position of the player
this.initialPosition = this.entity.getPosition();
};
// update code called every frame
Run.prototype.update = function(dt) {
// check if the left shift key is pressed
if (pc.input.isKeyPressed(pc.KEY_LSHIFT)) {
// move the player forward by 1 unit per frame
this.entity.setPosition(this.initialPosition.x + 1, this.initialPosition.y, this.initialPosition.z);
}
};
var Run = pc.createScript('run');
// initialize code called once per entity
Run.prototype.initialize = function() {
// get the current position of the player
this.initialPosition = this.entity.getPosition();
};
// update code called every frame
Run.prototype.update = function(dt) {
// check if the left shift key is pressed
if (pc.input.this.app.keyboard.isPressed(pc.KEY_LSHIFT)) {
// move the player forward by 1 unit per frame
this.entity.setPosition(this.initialPosition.x + 1, this.initialPosition.y, this.initialPosition.z);
}
};
Maybe you could shed some light on where you’re getting this code example/pseudo-code? It seems like you might be getting confused because you are using old tutorials, or tutorials from other engines. The for checking key presses in the update function looks like this:
What you are using doesn’t exist in the current build of the engine. If you are having trouble with keyboard input, feel free to check out this section of the User Manual:
The Editor’s code editor will also provide you with suggestions for key codes, and you can see a list of all of the key codes here in the API reference:
I am not familiar with the new functions and scripting, as I learned how to code JavaScript about 3 years ago using old tutorial videos so it is on me.
Right. My understanding is that there are a lot of old tutorial videos out there for the old scripting system that no longer works with current projects. I would suggest reviewing the Tutorials section and the User Manual to familiarize yourself with the structure of scripts and the tools that are currently available to you from the engine.