Forum Discussion
Converting a list to comma separated value using JavaScript
- 2 months ago
Probably a bit late on the response for you BenColey but if anybody else finds this post who needs something similar, I've included an example Storyline file.
In the example there are two Storyline variables unprocessedText and processedText.
The input text field, sets the Storyline variable unprocessedText and the processed text, after being worked on via JavaScript is saved to the processedText variable, displayed in the text box labelled Output.
There is a JavaScript function called processText which is initialised when the timeline starts on the slide.
window.processText = function() { const player = GetPlayer(); // set the unprocessedText Storyline variable const unprocessedText = player.GetVar('unprocessedText'); // process the data let processedText = unprocessedText .split('\n') // Split by line breaks .map(line => line.trim()) // Trim whitespace from each line .filter(line => line) // Filter out any empty lines .join(', '); // Join with a comma and space // set the processedText Storyline variable player.SetVar('processedText',processedText); }
The function is then called via the Process button "user clicks" trigger.
window.processText();
Probably a bit late on the response for you BenColey but if anybody else finds this post who needs something similar, I've included an example Storyline file.
In the example there are two Storyline variables unprocessedText and processedText.
The input text field, sets the Storyline variable unprocessedText and the processed text, after being worked on via JavaScript is saved to the processedText variable, displayed in the text box labelled Output.
There is a JavaScript function called processText which is initialised when the timeline starts on the slide.
window.processText = function()
{
const player = GetPlayer();
// set the unprocessedText Storyline variable
const unprocessedText = player.GetVar('unprocessedText');
// process the data
let processedText = unprocessedText
.split('\n') // Split by line breaks
.map(line => line.trim()) // Trim whitespace from each line
.filter(line => line) // Filter out any empty lines
.join(', '); // Join with a comma and space
// set the processedText Storyline variable
player.SetVar('processedText',processedText);
}
The function is then called via the Process button "user clicks" trigger.
window.processText();