Forum Discussion

AlejandroGon656's avatar
AlejandroGon656
Community Member
3 months ago

Text entry interaction with decimal places

Hello there,

I have one problem with Storyline and I am looking for help.

I created an interaction in which the user is asked how much voltage is accepted in one piece of equipment.

At first, I had integer numbers with no decimals. So, for example, "12". But if the user enters, say, "12.6", it would be technically correct, but Storyline is not able to do this natively.

I can't add 12.1, 12.2, 12.n because Storyline only allows 10 options. The correct answer in this case goes from 10 to 13, so I'd need many more slots than 10. And there is also the problem that some people will use the dot and others the comma.

I have also looked in the E-learning Heroes community for workarounds and/or JavaScript snippets, but haven't found anything that is really similar to my case.

I know I can instruct users in the question stem to use only whole numbers and avoid decimal places, but I thought I would ask the community, just in case anyone had managed to tame Storyline's ridiculously limited functionality.

Thank you!

  • Nedim's avatar
    Nedim
    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.

     

  • JesseWu's avatar
    JesseWu
    Community Member
    // 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?

    • AlejandroGon656's avatar
      AlejandroGon656
      Community Member

      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!!🙌

      • Nedim's avatar
        Nedim
        Community 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.

  • MichaelHinze's avatar
    MichaelHinze
    Community Member

    Using a NUMERIC entry box seems the easiest way to go here, as it does allow dots, but not commas. Or you could use a slider or dial to have users select a voltage value.