var DoorOpener = pc.createScript('DoorOpener');
DoorOpener.attributes.add('Door', {type: 'entity'});
if(this.gameStarted === true)
if (app.keyboard.isPressed(pc.KEY_E)) {
this.Door.enabled = false;
if (app.keyboard.isPressed(pc.KEY_Q))
this.Door.enabled = true;
I have no clue why it is not working.
saif
February 5, 2022, 3:50pm
#2
Hey, you will have to write the game logic within some function to make it work. You can write it in the function like this:
DoorOpener.prototype.update = function (dt) {
this.gameStarted = true;
if(this.gameStarted === true) {
if (app.keyboard.isPressed(pc.KEY_E)) {
this.Door.enabled = false;
if (app.keyboard.isPressed(pc.KEY_Q))
this.Door.enabled = true;
}
};
1 Like
Thanks for your response, but your code is giving this error: Uncaught SyntaxError: Unexpected end of input
SyntaxError: Unexpected end of input
saif
February 5, 2022, 5:50pm
#4
Seems like a bracket issue. Can you share your complete script code here?
1 Like
var DoorOpener = pc.createScript('DoorOpener');
DoorOpener.attributes.add('Door', {type: 'entity'});
DoorOpener.prototype.update = function (dt) {
this.gameStarted = true;
if(this.gameStarted === true) {
if (app.keyboard.isPressed(pc.KEY_E)) {
this.Door.enabled = false;
if (app.keyboard.isPressed(pc.KEY_Q))
this.Door.enabled = true;
}
};
saif
February 5, 2022, 5:54pm
#7
Can’t see any issue here except with adding “this” before the keyboard condition like this:
var DoorOpener = pc.createScript('DoorOpener');
DoorOpener.attributes.add('Door', {type: 'entity'});
DoorOpener.prototype.update = function (dt) {
this.gameStarted = true;
var app = this.app;
if(this.gameStarted === true) {
if (app.keyboard.isPressed(pc.KEY_E)) {
this.Door.enabled = false;
}
if (app.keyboard.isPressed(pc.KEY_Q))
this.Door.enabled = true;
}
};
If that doesn’t resolve the issue then you can share the link of the project to further look at
Is the script complete, because if it is I’ll test it.
https://launch.playcanvas.com/1327780?debug=true Here is the launch the black part on the side of r=the wall is the door, the code is supposed tomake it disable so, it is then able to let you leave, however it is not working.
I have a solution, I can do away with the script, and make the doors non-collision.
The end bracket of the first statement is missing.
saif
February 5, 2022, 6:09pm
#16
1 Like