Dynamic global variable

Home Forums Support Dynamic global variable

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2215
    TIm
    Guest

    Hi Henk and Erwin,

    Thanks for all the help you’ve given me so far. I have a question about how I might be able to incorporate dynamic variables that change across trials (or even blocks perhaps). In my experiment, participants score points for their performance on each trial and this score accumulates across trials. The nature of the stimulus that is displayed in a given trial depends on their aggregate trial score. Thus, I’d like to be able to somehow track the cumulative score as it updates from trial to trial. I’ll need to be able to use this information in the stimulus presentation and also to record it in the data file.

    I haven’t come across anything quite like this yet in the forum or in the tutorials. I think the ‘loop and merge’ functionality is close to what I need, in that it allows me to use pre-specified values as input to the stimulus that’s presented in a given trial. However, in my experiment, these values cannot be pre-specified (i.e., before the experiment) because they depend on the participant’s behaviour in previous trials. I have the feeling that the answer has something to do with the ‘getTrialData’/’setTrialData’ commands. But I don’t know how to create new variables to use with these commands.

    Thanks again for all your help,
    Cheers,
    Tim

    #2234
    Erwin Haasnoot
    Keymaster

    Hi Tim,

    I notice this issue hasn’t been properly documented yet. You’re correct in assuming setTrialData is close to what you need.

    We have defined a three-level data system in the QRTEngine. The first is TrialData, which is stored and reset per-trial. A higher level is BlockData (QRTEngine.setBlockData(‘field’,value) and QRTEngine.getBlockData(‘field’) for data that persists through a block, but is reset upon encountering a new block. The last level is Survey Data (QRTEngine.setSurveyData(‘field’,value) and QRTEngine.getSurveyData(‘field’)) for survey wide data storage, which is basically a wrapper around the Qualtrics.SurveyEngine.setEmbeddedData functions.

    It seems like you would need set and getBlockData for your survey.

    Let me know if you can figure it out from here!

    Best regards,

    Erwin

    #2248
    Tim
    Guest

    Hi Erwin,

    Thanks for the help! I think I’ve got the general idea. However, I’m having a bit of trouble with the implementation. Within my trial loop, I’m trying to set the values of certain variables in one question, and then call (or ‘get’) those values in the next question. For example, the question in which I set the values is coded as follows…

    ———————

    QRTE.Stimulus ({
    id: ‘SetParameters’, //Should be a unique ID, per stimulus in a trial block
    onShowFn: function() {
    QRTEngine.setTrialData(‘LeftGoalHeight’,200);
    QRTEngine.setTrialData(‘RightGoalHeight’,200);
    QRTEngine.setTrialData(‘LeftStartHeight’,108);
    QRTEngine.setTrialData(‘RightStartHeight’,108);
    QRTEngine.setTrialData(‘LeftWeeksTotal’,30);
    QRTEngine.setTrialData(‘RightWeeksTotal’,30);
    }
    });

    —————

    I then attempt to call the variables in the next question using the ‘getTrialData’ command. For example…

    ——
    QRTE.Stimulus ({
    id: ‘DecisionScreen’, //Should be a unique ID, per stimulus in a trial block
    onShowFn: function() {
    ….
    var x1 = QRTE.getTrialData(‘LeftGoalHeight’);
    var x2 = QRTE.getTrialData(‘RightGoalHeight’);
    var x3 = QRTE.getTrialData(‘LeftStartHeight’);
    var x4 = QRTE.getTrialData(‘RightStartHeight’);
    var x5 = QRTE.getTrialData(‘LeftWeeksTotal’);
    var x6 = QRTE.getTrialData(‘RightWeeksTotal’);
    ….
    }
    });

    ———

    However, when I retrieve the values of x1-x6, they come up as ‘undefined’. Am I missing something? Do I need to initialise the TrialData fields before I set them in the first question (e.g., in the survey flow or something?).

    Cheers,
    Tim

    #2249
    Tim
    Guest

    Hi Erwin,

    Thanks for the help! I think I’ve got the general idea. However, I’m having a bit of trouble with the implementation. Within my trial loop, I’m trying to set the values of certain variables in one question, and then call (or ‘get’) those values in the next question. For example, the question in which I set the values is coded as follows…

    ———————

    QRTE.Stimulus ({
    id: ‘SetParameters’, //Should be a unique ID, per stimulus in a trial block
    onShowFn: function() {
    QRTEngine.setTrialData(‘LeftGoalHeight’,200);
    QRTEngine.setTrialData(‘RightGoalHeight’,200);
    QRTEngine.setTrialData(‘LeftStartHeight’,108);
    QRTEngine.setTrialData(‘RightStartHeight’,108);
    QRTEngine.setTrialData(‘LeftWeeksTotal’,30);
    QRTEngine.setTrialData(‘RightWeeksTotal’,30);
    }
    });

    —————

    I then attempt to call the variables in the next question using the ‘getTrialData’ command. For example…

    ——
    QRTE.Stimulus ({
    id: ‘DecisionScreen’, //Should be a unique ID, per stimulus in a trial block
    onShowFn: function() {
    ….
    var x1 = QRTE.getTrialData(‘LeftGoalHeight’);
    var x2 = QRTE.getTrialData(‘RightGoalHeight’);
    var x3 = QRTE.getTrialData(‘LeftStartHeight’);
    var x4 = QRTE.getTrialData(‘RightStartHeight’);
    var x5 = QRTE.getTrialData(‘LeftWeeksTotal’);
    var x6 = QRTE.getTrialData(‘RightWeeksTotal’);
    ….
    }
    });

    ———

    However, when I retrieve the values of x1-x6, they come up as ‘undefined’. Am I missing something? Do I need to initialise the TrialData fields before I set them in the first question (e.g., in the survey flow or something?).

    Cheers,
    Tim

    #2259
    Erwin Haasnoot
    Keymaster

    Sorry about that, I was in a hurry when I wrote the piece and didn’t fact check it correctly.

    You will need to call QRTE.getTrialData / QRTE.setTrialData. QRTEngine.setTrialData, unlike what is claimed in my previous post, does not exist (nor does QRTEngine.getBlockData etc.), hence the ‘undefined’ values.

    Note that Trial Data is reset after each trial, so you would need to use Block Data

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Support’ is closed to new topics and replies.