Sprite Changer Script

var D = pc.app.keyboard.isPressed(pc.KEY_D);
if(D){
    this.entity.sprite.frame = 4;
    if(this.entity.sprite === 5){
        setTimeout(this.entity.sprite.frame = 4, 100);
    }
    //maybe translate local here idk lol :P
}

can you help me with this script. im trying to change a sprite on keyboard input.
like it plays a certain animation when a button is pressed.

What is your current result?