quick way for setting multiple inputs

29 views
Skip to first unread message

Snir Barzilay

unread,
Jan 9, 2020, 3:05:20 PM1/9/20
to Minno.js
Hello,
I am using minno time for a fear conditioning task. During extinction I would like participants to press a number between 1-9 to note their anxiety levels. 
However, I would like to use one custom input function instead of writing nine lines of code, each with a different handle for a different key.

I have tried using:
{type:'setInput',input:{
        handle: 'AnxietyRate',
        on: function(data,event){
            // do your mojo here and then
            // where e is the raw event, and 'eventType' is the name of this event

            var keynum = event.key;
            console.log(keynum)
            callback(keynum, 'keypressed');
        },
        off: function(){
            // remove your listener (if you need to keep state you can encapsulate the whole input object in a module)
        }
        }

But I don't really know how to open a listener to the relevant keys or how should I define the callback function.

Thanks in advance,

Snir

Elad Zlotnick

unread,
Jan 13, 2020, 10:36:51 AM1/13/20
to Minno.js
Hi Snir,

Welcome to our forum.
The simples way to do what you want has two steps.

First setup your input as follows:
                {handle:'number', on:'keypressed', key:['1','2','3','4','5','6','7','8','9']}

Note that the numbers are quoted. This is necessary so that Minno does not interpret them as key codes instead of numbers. 

Next setup an interaction as follows:
{
    conditions: [{type:'inputEquals',value:'number'}],
    actions:[
        {type:'setTrialAttr', setter: function(trialData,inputData){
            trialData.score = inputData.event.key;
        }}
    ]
}

inputData.event holds the event triggering the keypress.
We set the key pressed into data.score

You can then use this value however you like.

Good luck
Elad

Snir Barzilay

unread,
Jan 14, 2020, 4:09:02 AM1/14/20
to Minno.js
Hey thanks for the reply. However, while implementing I encounter a different error:

This is part of the code I used.
{
conditions:[{type:'inputEquals',value:'showMyStim'}],

actions: [
{type:'resetTimer'},
{type:'hideStim',handle: 'fixation'},
{type:'showStim', handle: 'cue'},
{type:'showStim', handle: 'layoutanswers'},
{handle:'number', on:'keypressed', key:['1','2','3','4','5','6','7','8','9']},
{type:'setInput',input:{handle:'time',on:'timeout',duration:4000}},
{type:'setTrialAttr',setter:{rated:'no'}},


]
},
{
conditions: [
{type:'inputEquals',value:'number'}
],
actions: [
{type:'custom',fn:function(){console.log('no')}},
{type:'setTrialAttr', setter: function(trialData,inputData){
            trialData.score = inputData.event.key;
        }},
        {type:'log'},
{type:'setTrialAttr',setter:{rated:'yes'}},
{type:'removeInput',handle:['number']},
{type:'hideStim',handle:'layoutanswers'}
]
},

This is the error:

Trial.js:14 Uncaught Error: Interactions not defined
    at new Trial$1 (Trial.js:14)
    at playPhase.js:71
    at Object.<anonymous> (stream.js:102)
    at Object.i [as derive] (stream.js:68)
    at u (stream.js:55)
    at r (stream.js:43)
    at t (stream.js:9)
    at p (playPhase.js:64)
    at playPhase.js:80
    at Object.<anonymous> (stream.js:102)

Michael Pinus

unread,
Jan 14, 2020, 4:37:09 AM1/14/20
to Minno.js

I think this has to do with inserting

{handle:'number', on:'keypressed', key:['1','2','3','4','5','6','7','8','9']},

in actions, and not in input:

API.addTrialSets('Trial',
    {        
        layout: [
                   {media: {word:'This is a fear conditioning task'},
                    location:{top:94},css: {color:'#0000ff', 'font-size':'1em'}}
            ],
        input: [
            {handle:'number', on:'keypressed', key:['1','2','3','4','5','6','7','8','9']}
        ],
        interactions: [
            {
                    conditions:[{type:'inputEquals',value:'showMyStim'}],

                    actions: [
                            {type:'resetTimer'},
                            {type:'hideStim',handle: 'fixation'},
                            {type:'showStim', handle: 'cue'},
                            {type:'showStim', handle: 'layoutanswers'},
                            {type:'setInput',input:{handle:'time',on:'timeout',duration:4000}},
                            {type:'setTrialAttr',setter:{rated:'no'}},

                    ]
                },
                {
                    conditions: [
                        {type:'inputEquals',value:'number'}
                    ],
                    actions: [

                        {type:'custom',fn:function(){console.log('no')}},
                        {type:'setTrialAttr', setter: function(trialData,inputData){
                            trialData.score = inputData.event.key;

                        }},                        
                        {type:'log'},
                        {type:'setTrialAttr',setter:{rated:'yes'}},
                        {type:'removeInput',handle:['number']},
                        {type:'hideStim',handle:'layoutanswers'}
                    ]
                }

Snir Barzilay

unread,
Jan 14, 2020, 5:04:26 AM1/14/20
to Minno.js
Thanks! your'e right. 
I tried implementing it later in the interactions so I wouldn't record it during presentation of fixation. I used the 'setInput' in the actions array. However, I still receive the same error as before 
conditions:[{type:'inputEquals',value:'showMyStim'}],

actions: [
{type:'resetTimer'},
{type:'hideStim',handle: 'fixation'},
{type:'showStim', handle: 'cue'},
{type:'showStim', handle: 'layoutanswers'},
{type:'setInput', input:{handle:'number', on:'keypressed', num:['1','2','3','4','5','6','7','8','9']}},
{type:'setInput', input:{handle:'time',on:'timeout',duration:4000}},
{type:'setTrialAttr',setter:{rated:'no'}},


]
},

Mayan Navon

unread,
Jan 14, 2020, 5:22:22 AM1/14/20
to Minno.js
Hi Snir,

Could you please provide a link to the study files? This way we could see the greater context of your code and maybe figure out what went wrong. 


Thanks,
Mayan


On Thursday, January 9, 2020 at 10:05:20 PM UTC+2, Snir Barzilay wrote:

Snir Barzilay

unread,
Jan 14, 2020, 5:29:42 AM1/14/20
to Minno.js

elad...@gmail.com

unread,
Jan 16, 2020, 3:32:06 AM1/16/20
to Minno.js
It turned out that the problem was a mixer without a mixer property:
{ data:[...]}

Minno didn't recognise it as a mixer, and therefore looked for the trial interactions (which of course it didn't find) - hence the error.

Best,
Elad
Reply all
Reply to author
Forward
0 new messages