Text entry must contain

Sep 12, 2019

Hallo - I've been trying to find or think up a workaround for this but I can't! Can anybody help?

I have a text entry field that I want users to complete - they can write anything at all, but it must contain specific words (let's say, for example; "Specific Words"!).

I don't want them to be limited to writing 'Specific Words' (although they would still pass if they did) - I want to encourage them to write more, but be judged correctly if 'Specific Words' is included in the text.

Is there any way I could do this?

13 Replies
Jerry Beaucaire

Attached is an example of how I solved this on one question.   

  1. The slide is just a multiple choice.   I will actually set the answer to correct or wrong based on what they do in the fake interaction... see next.
  2. There is an extra layer in this question where the interaction actually occurs.  Here there is a textentry box and javascript that examines the user's input when they submit it.

    In my javascript I check for the word "Plug" or the word "blind", if either word is anywhere in the typed response, the script then changes the multiple choice on the base layer to the correct answer.

    Check it out.
Steven Haigh

Hi Jerry, Not sure if you can help again.  I am trying to get the java scrip to include upper case and lower case, so I have just copied and pasted the line relating to the word and changed the first letter to upper case.  This now only accepts the upper case word and ignores the lower case.  Are you able to help?

 

var player = GetPlayer();

var str = player.GetVar("draincoolant");
var n = str.search("drain");
var n = str.search("Drain");
var m = str.search("coolant");
var m = str.search("Coolant");

if(n >= 0){
player.SetVar("draincoolant", "Drain coolant"); 
}else if(m >= 0){
player.SetVar("draincoolant", "Drain coolant"); 
}else{
player.SetVar("draincoolant", str);
}

Steven Haigh

I've also tried changing the Var n to a different letter as I appreciate that a duplicate of the letter will confuse it.  So:

var n = str.search("drain");

var o = str.search("Drain");

var p = str.search("coolant");

var q = str.search("Coolant");

etc...

And then updated the second part accordingly,  but this still didn't work.  I'm sure that there is a simple solution.

Walt Hamilton

Steven,

These lines won't work, because the second one changes what the first one did, so the lower case is never searched for.

var n = str.search("drain");
var n = str.search("Drain");

 

The attempt with two separate variables probably works, but these lines change the SL variable to the upper case regardless of which one is found.

player.SetVar("draincoolant", "Drain coolant");
}else if(m >= 0){
player.SetVar("draincoolant", "Drain coolant");
}else{

Try      var str = player.GetVar("draincoolant").toLowerCase(); if you want to ignore case. The problem is that the answer is changed to all lower case, which is only a problem if you come back at the end and reset the SL variable. In that case, I would use strOri to store the original value, then use str = strOri.toLowerCase(); Search str, and use strOri to write to SL.