Text undefined - pavlovia

URL of experiment: https://run.pavlovia.org/oztel/new_global_probfb/html

Description of the problem:
hi,

I am building an experiment where apply a kind of a yoking procedure. My task is a temporal reproduction task where participants receive a feedback regarding the direction of their deviation of the temporal reproduction from a target duration (“short” or “long”,basically).
I am trying to yoke the probability of “short” and “long” feedback appearance to the proportion of correct responses from a previous experiment that i collected data from. So, the congruency of the feedback to be received is defined by the proportion correct of some previous participant (i.e., for example if the correct proportion of the previous participant in “short” response is 0.8, the current participant should receive 80% “short” feedback whenever they make a short reproduction, and 20% “long” feedback whenever they make a short reproduction).

I have an array of correct proportion named “complete_list”. I am retrieving data from that list according to the participant ID

part_no = parseInt(expInfo["participant"]);

via the following line:

correct_probs = complete_list[(part_no - 1)];

where the 0th element of correct_probs is the proportion of correct “long” judgements and 1st of it is the proportion correct “short” of the part_no’th participant in the previous experiment:

long_prob = correct_probs[0];
short_prob = correct_probs[1];

I define these in “experimentInit” section.

In the end of the routine where participants perform the reproduction, I do this to define which feedback the participant will receive:

(i is the number of trial, “KISA” means “short” basically and “UZUN” is long. “reproOffset.rt” is the reproduced duration by the participant. 2 seconds is the target duration. from 10th trial forward, I give feedback according to the zscore of the reproduction).

if ((i < 10)) {
        if ((reproOffset.rt < 2)) {
            rand_prob = Math.random();
            if ((rand_prob < short_prob)) {
                feedback_text = "KISA";
            } else {
                feedback_text = "UZUN";
            }
        } else {
            if ((reproOffset.rt > 2)) {
                rand_prob = Math.random();
                if ((rand_prob < long_prob)) {
                    feedback_text = "UZUN";
                } else {
                    feedback_text = "KISA";
                }
            }
        }
    } else {
        zRepro = arr.zscore(allRepro);
        if ((zRepro[i] < 0)) {
            rand_prob = Math.random();
            if ((rand_prob < short_prob)) {
                feedback_text = "KISA";
            } else {
                feedback_text = "UZUN";
            }
            psychoJS.experiment.addData("zRepro_1", zRepro[i]);
        } else {
            if ((zRepro[i] > 0)) {
                rand_prob = Math.random();
                if ((rand_prob < long_prob)) {
                    feedback_text = "UZUN";
                } else {
                    feedback_text = "KISA";
                }
            }
        }
        psychoJS.experiment.addData("zRepro_1", zRepro[i]);
    }
    i += 1;

in the beginning of feedback routine, I have:

 testFeedback_Text.setText((('Üretiminiz hedef süreye kıyasla ' + feedback_text) + ' idi.'));

where feedback_text is pasted in the sentence.

So according to my code, I should see a feedback like “Üretiminiz hedef süreye kıyasla KISA (or UZUN) idi”, but instead I see this text “Üretiminiz hedef süreye kıyasla undefined idi”.
I declared all the variables with “var” statement and I set the feedback text to be set every repeat (not constant).

I tried moving the definition of variables to the routine end of reproduction as well but nothing has changed.

I have been working on this code for about 10 days now and I couldnt figure out whats happening actually. I created another experiment where I do exactly the same thing where I see the KISA and UZUN words instead of an “undefined” but that code always gives incongruent feedback regardless of the proportions I define (and it reads the probabilities correctly).
I am inserting its link too: https://run.pavlovia.org/oztel/global_probabilisticfb/html

PS: all works fine locally in psychopy Builder.

I know that it sounds a bit complicated but any help would be much appreciated :frowning:

thanks so much in advance, tutku

Could you please share the GitLab repo of your experiment? This page explains how. My username is: tpronk

dear @thomas_pronk;

thanks for your reply. added you as a developer to the project. the repo link is:

Thnx! I see quite a lot of components in your experiment. Could you tell me in which routine you’re assigning a value to feedback_text?

lol thats very much so indeed! in the reproductionDone component I am assigning a value to the feedback_text variable. in builder, i inserted a code component, in the end routine tab, I do the assignment for the feedback_text

Thnx! I think the issue is the scope of the feedback_text variable; it only exists within the routine reproductionDone. You could try this instead:

  • Use window.feedback_text instead of feedback_text, then your variable has global scope
  • You can’t use window.feedback_text as placeholder in a text stimulus, but you can use it via a construct like this: textStimulus.text = feedback_text in the begin routine tab of the routine that presents you text stimulus