Hi all,
I am having a problem - keyboard.wasPressed is running the same way as keyboard.isPressed. Could you please tell me how to fix my code?
Rgds,
var CodeJjkk = pc.createScript('codeJjkk');
// initialize code called once per entity
CodeJjkk.prototype.initialize = function() {
};
// update code called every frame
CodeJjkk.prototype.update = function(dt) {
//declaration
var codpos = 1;
var count = 1;
var VarOfGreatness = this.app.keyboard.wasPressed(pc.KEY_1);
//logic
for (count = 0; count < 10; count ++){
if (VarOfGreatness){
if (codpos === 1 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward1');
fd.setLocalPosition(-1.106, 1.842, -5.225);
codpos ++;
}
else if (codpos === 2 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward2');
fd.setLocalPosition(-0.57, 1.84, -5.225);
codpos ++;
}
else if (codpos === 3 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward3');
fd.setLocalPosition(-0.071, 1.84, -5.225);
codpos ++;
}
else if (codpos === 4 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward4');
fd.setLocalPosition(0.429, 1.84, -5.225);
codpos ++;
}
else if (codpos === 5 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward5');
fd.setLocalPosition(0.95, 1.84, -5.225);
codpos ++;
}
else if (codpos === 6 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward6');
fd.setLocalPosition(-1.1, 1.392, -5.225);
codpos ++;
}
else if (codpos === 7 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward7');
fd.setLocalPosition(-0.608, -1.392, -5.225);
codpos ++;
}
else if (codpos === 8 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward8');
fd.setLocalPosition(0.02, 1.392, -5.225);
codpos ++;
}
else if (codpos === 9 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward9');
fd.setLocalPosition(0.525, 1.392, -5.225);
codpos ++;
}
else if (codpos === 10 && this.app.keyboard.wasReleased === 0){
fd = this.app.root.findByName('Forward10');
fd.setLocalPosition(1.007, 1.392, -5.225);
codpos ++;
}
}
}
};
// swap method called for script hot-reloading
// inherit your script state here
// CodeJjkk.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/