Forum Discussion
JesseWu
4 days agoCommunity Member
// Function to set the Storyline variable
function setStorylineVariable(variableName, value) {
GetPlayer().SetVar(variableName, value);
}
// Check if listeners are already added
if (!window.keyListenersAdded) {
// Combined event listener for keydown and keyup
document.addEventListener('keydown', function(event) {
if (event.key === 'A' || event.key === 'a') {
setStorylineVariable('isKeyAPressed', true);
}
});
document.addEventListener('keyup', function(event) {
if (event.key === 'A' || event.key === 'a') {
setStorylineVariable('isKeyAPressed', false);
}
});
// Mark listeners as added
window.keyListenersAdded = true;
}
Personal approach:
Introduce a new T/F variable with this JS script: When key A is pressed, set it to true; When released, set it to false.
The new trigger will be: When variable changes, if isKeyAPressed is true, [exec function here].