Reply To: Dynamic global variable

Home Forums Support Dynamic global variable Reply To: Dynamic global variable

#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