Forum Discussion
Text entry interaction with decimal places
- 2 months ago
No need to specify conditions in the trigger—it's already set up in Form View. All you need to do is submit the interaction, and Storyline will automatically validate whether the answer falls within the correct range.
// Get the text variable "dataEntry1" and the boolean variable "ifConditionMet"
var player = GetPlayer();
var dataEntry1 = player.GetVar("dataEntry1");
var ifConditionMet = player.GetVar("ifConditionMet");
// Clean the value of dataEntry1, allowing only numbers and decimal points
dataEntry1 = dataEntry1.replace(/[^0-9.,]/g, '');
// Replace comma with a dot if present
dataEntry1 = dataEntry1.replace(',', '.');
// Check if the cleaned value is a valid number
if (isNaN(dataEntry1) || dataEntry1 === '') {
alert("Please enter a valid number.");
} else {
// Convert the cleaned text variable to a number
var numberVar = parseFloat(dataEntry1);
// Check if the number is within the expected range
if (numberVar >= 10 && numberVar <= 13) {
ifConditionMet = true;
} else {
ifConditionMet = false;
}
// Set the boolean variable "ifConditionMet" in Storyline
player.SetVar("ifConditionMet", ifConditionMet);
}
something like this?
Hey Jesse, sorry for the delay. I was out of office. While this didn't exactly solve my issue, this snippet will prove useful for other areas. Thank you very much for putting time into it!!🙌
- Nedim2 months agoCommunity Member
I'm curious—why not use a numeric entry interaction instead? This approach would require the learner to input the correct numeric value and would allow you to specify an acceptable range of answers as well.
- AlejandroGon6562 months agoCommunity Member
Hey Nedim,
Thanks for your answer. I am assuming that you are bypassing the "Form view" when configuring the interaction and instead doing it all by triggers, right? As in:
And then, to add scores manually if they succeed so that they are reflected in the Results slide. Is that so?
- Nedim2 months agoCommunity Member
No need to specify conditions in the trigger—it's already set up in Form View. All you need to do is submit the interaction, and Storyline will automatically validate whether the answer falls within the correct range.