Script for checking user-input subject ID against valid list of acceptable subject ID's


Author
Message
jeff.smith
jeff.smith
Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)
Group: Forum Members
Posts: 33, Visits: 190
I will be providing participants with Subject ID and Group ID to input in Inquisit Web. 

1. I want a script to run immediately after inputting Subject ID and Group ID to display that either:
A) Yes, your Subject ID is correct, please continue. <Script goes onto Consent script>
OR
B) No, this is not a correct Subject ID. Please try again. <Script abort>

For this, I cannot seem to get the right branch script to call the SubjectID (or 'subject' as it appears in the data column) and compare it against a list of acceptable ID's that I have put into an item element. I may have other errors below as I am still a complete beginner and am still learning the logic/syntax of Inquisit :P  

2. Also, do I need to add the long javascript code from the Inquisit help file, "Assigning subject numbers in Web Experiments", to allow participants accessing the Web experiment to enter their own SubjectID and GroupID? Or are these different from "Subject Number"?

Script so far:

<instruct>
/nextkey=(" ")
</instruct>

<page valid>
The Subject ID (<% script.subjectID %> ) you have input is correct! Please press Spacebar to continue
with the survey.
</page>

<page error>
The Subject ID (<% script.subjectID %> ) you have input is incorrect.
Please input carefully the Subject ID you were provided.^^
If you believe this is an error, please contact the coordinator, NAME HERE,
at EMAIL HERE and provide your Group ID and Subject ID.^^
Press Spacebar to end the survey.
</page>

<item ID>
/ 1="AAA"
/ 2="BBB"
</item>

<expt >
/ blocks = [1 = Validation]
</expt>

<trial Validation>
/branch=[if (<% script.subjectid %> = item.ID) = true block.startsurvey]
/branch=[if (<% script.subjectid %> = item.ID) = false block.error]
/timeout = 100
/recorddata=false
</trial>

<trial error>
/ontrialbegin = [script.abort();]
/timeout = 1
/ontrialend = [script.abort();]
/recorddata=false
</trial>

<block Validation>
/trials = [1 = Validation]
</block>

<block startsurvey>
/ preinstructions = (valid)
/recorddata = false
</block>

<block error>
/ preinstructions = (error)
/trials = [1 = error]
/recorddata = false
</block>

jeff.smith
jeff.smith
Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)
Group: Forum Members
Posts: 33, Visits: 190
Still need help with #2.

Managed to get #1 to work but I am confused WHY it worked...

Changes are in bold. Why is that the contains function statement seems backwards (highlighted portion)? Why did I have to set it to "= false ) block.startsurvey" when the !contains value will return TRUE if I have put in IDs AAA or BBB?:

<instruct>
/nextkey=(" ")
</instruct>

<page valid>
The Subject ID (<% script.subjectID %> ) you have input is correct! Please press Spacebar to continue
with the survey.
</page>

<page error>
The Subject ID (<% script.subjectID %> ) you have input is incorrect. 
Please input carefully the Subject ID you were provided.^^
If you believe this is an error, please contact the coordinator, NAME HERE,
at EMAIL HERE and provide your Group ID and Subject ID.^^
Press Spacebar to end the survey.
</page>

<item ID>
/ 1="AAA"
/ 2="BBB"
</item>


<values>
/valdsids ="AAA,BBB"
</values>


<expt First>
/ blocks = [1 = Validation]
</expt>

<trial Validation>
/branch=[if (<% script.subjectid %> = item.ID) = true block.startsurvey]
/branch=[if (<% script.subjectid %> = item.ID) = false block.error]

/timeout = 100
/recorddata=false
</trial>

<trial error>
/ontrialbegin = [script.abort();]
/timeout = 1
/ontrialend = [script.abort();]
/recorddata=false
</trial>

<block Validation>
/trials = [1 = Validation]
/branch=[if (!contains(values.validsids,script.subjectid) == false) block.startsurvey]
/branch=[if (!contains(values.validsids,script.subjectid) == true) block.error]

</block>

<block startsurvey>
/ preinstructions = (valid)
/recorddata = false
</block>

<block error>
/ preinstructions = (error)
/trials = [1 = error]
/recorddata = false
</block>

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 105K
Re. #1: See https://www.millisecond.com/forums/Topic17596.aspx for the sake of completeness.

Re. #2: No, these are not different from subject and group number. You do not need to write any JavaScript. You simply select the "subject-entered" option when you upload your script to the millisecond.com server and configure the web experiment's settings. Note that all of this happens outside of the script. Once the script is running, it is not possible to change the ID, albeit you can choose to abort the script based on the ID (you've already figured out how to do this under #1).

BUT: If I'm reading the instructions you included in your code correctly, you are assigning each participant an individual, unique ID beforehand via email. If so, the much more reliable option would be to provide each participant with an individualized link that already includes her or his unique ID via URL query parameter. I.e., you'd send

https://research.millisecond.com/yourusername/yourexperimentname.web?ID=AAA

to participant AAA,

https://research.millisecond.com/yourusername/yourexperimentname.web?ID=BBB

to participant BBB, and so forth.

All you'd need to do then is set your launch page to read the value of the ID query parameter when you upload / configure your experiment. This should obliterate any need for additional validation logic and greatly reduce the risk of human error (e.g. participants making typos in their IDs).

jeff.smith
jeff.smith
Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)
Group: Forum Members
Posts: 33, Visits: 190
Thanks, Dave.

Could you explain why the following works? I would have thought the string "(!contains(values.validsids,script.subjectid)" would return "TRUE" if the subjectid entered matches the accepted subjectid, but here I had to set it equal to FALSE for the script to work properly and send the participant to the correct subsequent block. 

/branch=[if (!contains(values.validsids,script.subjectid) == false) block.startsurvey]
/branch=[if (!contains(values.validsids,script.subjectid) == true) block.error]

I also do not understand the need for the double equal sign. The script did not work with a single equal. 

Can you tell I have zero programming knowledge? ;) [I still think I'm doing pretty good having known nothing a week ago!]
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 105K
The leading ! in "!contains(...)" is a logical negation.

Observe the difference:

<text mytext>
/ items = ("<% contains(~"catalog~", ~"cat~") %>~n<% !contains(~"catalog~", ~"cat~") %>")
/ size = (50%, 40%)
</text>

As for the difference between "=" and "==":

"=" is the *assignment* operator. You use it to *assign* a value to a variable as in "values.myvalue = 42". The variable "myvalue" henceforth represents the numerical value 42.

"==" is a *logical* comparison operator. You use it to check if a statement is 'false' or 'true', i.e., if the left side is equal to the righ side:

"cat" == "dog" -> false
"cat" == "cat" -> true

You'll find this covered in the "Operators" topic in the Inquisit documenation.

Hope this helps.

jeff.smith
jeff.smith
Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)Distinguished Member (4K reputation)
Group: Forum Members
Posts: 33, Visits: 190
Very helpful! I overlooked 'operators'. I have now familiarized myself with it :)

Also, I'll just drop this here, but https://www.millisecond.com/support/docs/v5/html/language/attributes/format.htm leads to nothing in the help file and online. The v4 version works though: https://www.millisecond.com/support/docs/v4/html/language/attributes/format.htm 
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search