I need help in editing this source code (cause idk anything about programming)

Discussion in 'Tech Discussion' started by flowersonyourgrave, Nov 5, 2022.

  1. flowersonyourgrave

    flowersonyourgrave Well-Known Member

    Joined:
    Mar 18, 2020
    Messages:
    18
    Likes Received:
    30
    Reading List:
    Link
    Hello! I need help and idk about programming but I need this for our research. My dilemma is that I need it to be only 10 matches and 15 no matches but the program is programmed to give random matches and no matches. Got it from https://www.psytoolkit.org/experiment-library/touch_nback2.html . Thank u so much for helping this poor hooman.

    options
    bitmapdir stimuli
    sounddir stimuli
    set &maxrt 760 # stimulus presentation
    set &iti 2000 # intertrial interval
    set &choosechance 3 # 1 in 4 are matching
    mouse on

    sounds
    sound_good good.mp3
    sound_bad wrong.mp3

    fonts
    arial 18

    bitmaps
    letterA ## 15 letters
    letterB
    letterC
    letterD
    letterE
    letterH
    letterI
    letterK
    letterL
    letterM
    letterO
    letterP
    letterR
    letterS
    letterT
    overlay
    instruction1
    instruction2
    instruction3

    ## a part is a reusable piece of code. In this case, it gives for the
    ## 3 blocks the feedback

    part myfeedback
    feedback
    text align left
    set &Total1 count ; select c8 == 1 && c1 == BLOCKNUMBER ## number of trials where there was a 2back item
    set &Total2 count ; select c8 > 1 && c1 == BLOCKNUMBER ## number of trials where there was NOT a 3back item
    set &Matches count ; select c4 == 1 && c1 == BLOCKNUMBER ## number of matches
    set &Misses count ; select c5 == 1 && c1 == BLOCKNUMBER ## number of misses
    set &FalseAlarms count ; select c6 == 1 && c1 == BLOCKNUMBER ## number of false alarms
    set &MatchesPerc expression &Matches / &Total1 * 100.0
    set &MissesPerc expression &Misses / &Total1 * 100.0
    set &FalseAlarmsPerc expression &FalseAlarms / &Total2 * 100.0
    text -250 -200 "There were 25 trials in total in this block"
    text -250 -150 &Total1 ; prefix "Total trials that had a match:"
    text -250 -100 &Total2 ; prefix "Total trials that had no match:"
    text -250 -50 &Matches ; prefix "Number of correctly matched items:"
    text -250 -0 &Misses ; prefix "Number of missed items:"
    text -250 50 &FalseAlarms ; prefix "Number of false alarms:"
    text -250 100 &MatchesPerc ; prefix "Percentage correct matches:" ; postfix " %"
    text -250 150 &MissesPerc ; prefix "Percentage missed items:" ; postfix " %"
    text -250 200 &FalseAlarmsPerc ; prefix "Percentage false alarms:" ; postfix " %"
    text -250 250 "Click mouse to continue and show data"
    wait_for_key mouse
    end

    task nback_learning
    set &trialcount increase
    set $currentletter random 1 15 ## choose randomw letter, might be overridden
    ############################################################################
    ## is this condition a yes condition?
    set $memory random 1 &choosechance ## 1 in &choosechance trials will be matching trial
    ## if a 2back trial (there must have been at least 2 trials before for this to be possible)
    if $memory == 1 && &trialcount > 2
    set $currentletter &nback2
    set $requiredresponse 1 ## this is a MATCH, so response is required
    fi
    ## if a NON 2back trial
    if $memory != 1 || &trialcount <= 2 ## chose a letter but not that of 2 trials ago
    set $currentletter random 1 15
    while $currentletter == &nback2 ## choose anything but NOT that of 2 back
    set $currentletter random 1 15
    while-end
    set $requiredresponse 2 ## this is a NON-match, so people need to withhold
    fi
    ############################################################################
    ## this part is the only part that is different between learning and non-learning
    draw off
    show bitmap $currentletter ## stimulus 1
    ## now show previous trials
    if &trialcount > 1
    show bitmap &nback1 -100 0 # show 1-back left of stimulus
    show bitmap overlay -100 0 # greyed out
    fi
    if &trialcount > 2
    show bitmap &nback2 -200 0 # show 2-back left of stimulus
    show bitmap overlay -200 0 # greyed out
    fi
    draw on
    ######################################################################
    readmouse l 1 &maxrt ## click the first bitmap in this task
    ############################################################################
    ## the different possible response outcomes
    ##
    if $requiredresponse == 1 and STATUS != TIMEOUT
    set $score 1 ## means good
    set $match 1
    sound sound_good
    fi
    if $requiredresponse == 1 and STATUS == TIMEOUT
    set $score 0 ## means wrong -- miss
    set $miss 1
    sound sound_bad
    fi
    if $requiredresponse == 2 and STATUS == TIMEOUT
    set $score 1 ## means good
    fi
    if $requiredresponse == 2 and STATUS != TIMEOUT
    set $score 0 ## means wrong
    set $false_alarm 1
    sound sound_bad
    fi
    #
    ######################################################################
    #
    set $extrawait expression &maxrt - RT ## how much time is left between max RT and now?
    delay $extrawait ## wait until letter has been on screen total of 2000 ms
    clear screen
    delay 2000 ## wait 2000 ms
    #
    ### now save the letter for next trial
    #
    set &nback2 &nback1
    set &nback1 $currentletter
    ### save the data
    save BLOCKNUMBER &trialcount $score $match $miss $false_alarm RT $memory $currentletter &nback1 &nback2

    task nback_normal
    set &trialcount increase
    set $currentletter random 1 15 ## choose randomw letter, might be overridden
    ############################################################################
    ## is this condition a yes condition?
    set $memory random 1 &choosechance ## 1 in &choosechance trials will be matching trial
    ## if a 2back trial (there must have been at least 2 trials before for this to be possible)
    if $memory == 1 && &trialcount > 2
    set $currentletter &nback2
    set $requiredresponse 1 ## this is a MATCH, so response is required
    fi
    ## if a NON 2back trial
    if $memory != 1 || &trialcount <= 2 ## chose a letter but not that of 2 trials ago
    set $currentletter random 1 15
    while $currentletter == &nback2 ## choose anything but NOT that of 2 back
    set $currentletter random 1 15
    while-end
    set $requiredresponse 2 ## this is a NON-match, so people need to withhold
    fi
    ############################################################################
    ## this part is the only part that is different between learning and non-learning
    draw off
    show bitmap $currentletter ## stimulus 1
    draw on
    ######################################################################
    readmouse l 1 &maxrt ## click the first bitmap in this task
    ############################################################################
    ## the different possible response outcomes
    ##
    if $requiredresponse == 1 and STATUS != TIMEOUT
    set $score 1 ## means good
    set $match 1
    sound sound_good
    fi
    if $requiredresponse == 1 and STATUS == TIMEOUT
    set $score 0 ## means wrong -- miss
    set $miss 1
    sound sound_bad
    fi
    if $requiredresponse == 2 and STATUS == TIMEOUT
    set $score 1 ## means good
    fi
    if $requiredresponse == 2 and STATUS != TIMEOUT
    set $score 0 ## means wrong
    set $false_alarm 1
    sound sound_bad
    fi
    #
    ######################################################################
    #
    set $extrawait expression &maxrt - RT ## how much time is left between max RT and now?
    delay $extrawait ## wait until letter has been on screen total of 2000 ms
    clear screen
    delay 2000 ## wait 2000 ms
    #
    ### now save the letter for next trial
    #
    set &nback2 &nback1
    set &nback1 $currentletter
    ### save the data
    save BLOCKNUMBER &trialcount $score $match $miss $false_alarm RT $memory $currentletter &nback1 &nback2

    block training
    set &trialcount 0 # make sure you use this again if you have another block
    message instruction1 mouse
    message instruction2 mouse
    tasklist
    nback_learning 25
    end
    part myfeedback

    block normal1
    set &trialcount 0 # make sure you use this again if you have another block
    message instruction3 mouse
    tasklist
    nback_normal 25
    end
    part myfeedback

    block normal2
    set &trialcount 0 # make sure you use this again if you have another block
    message instruction3 mouse
    tasklist
    nback_normal 25
    end
    part myfeedback
     
    Tafyunn likes this.
  2. Ca5e

    Ca5e Active Member

    Joined:
    Aug 10, 2022
    Messages:
    74
    Likes Received:
    60
    Reading List:
    Link
    sir this is wendy's
     
    Jr194 likes this.
  3. Neiri

    Neiri Well-Known Member

    Joined:
    Jan 20, 2016
    Messages:
    3,164
    Likes Received:
    2,075
    Reading List:
    Link
    Go to stackoverflow.com. Be precise and say everything. It is full of IT equivalent of Dr.House and Gordon Ramsay so expect condescending remarks and downvotes.
     
  4. loumi

    loumi Active Member

    Joined:
    Dec 17, 2015
    Messages:
    2
    Likes Received:
    1
    Reading List:
    Link
    The random comes from this part :
    Code:
    set $memory random 1 &choosechance ## 1 in &choosechance trials will be matching trial
      ## if a 2back trial (there must have been at least 2 trials before for this to be possible)
      if $memory == 1 && &trialcount > 2
        set $currentletter &nback2
        set $requiredresponse 1 ## this is a MATCH, so response is required
      fi
      ## if a NON 2back trial
      if $memory != 1 || &trialcount <= 2 ## chose a letter but not that of 2 trials ago
        set $currentletter random 1 15
        while $currentletter == &nback2 ## choose anything but NOT that of 2 back
          set $currentletter random 1 15
        while-end
        set $requiredresponse 2 ## this is a NON-match, so people need to withhold
      fi
    As you can see, the $memory variable is set randomly. If it's value is equal to 1, it's a match. Else it's not.

    If you want to have 10 matches and 15 non matches, you have to keep count of them and add a condition to your if-else.
     
    flowersonyourgrave likes this.
  5. flowersonyourgrave

    flowersonyourgrave Well-Known Member

    Joined:
    Mar 18, 2020
    Messages:
    18
    Likes Received:
    30
    Reading List:
    Link
    Thank you for explaining! How do I set the code for this one?
     
  6. loumi

    loumi Active Member

    Joined:
    Dec 17, 2015
    Messages:
    2
    Likes Received:
    1
    Reading List:
    Link
    I made the changes in a github. However, I can't post links so you have to add /ailectra/touch_nback2 to the github base url.

    As you can see, I added two variables &nbacktrialcount and &notnbacktrialcount set to 0 in the blocks.
    Then in the tasks, I changed the first condition of the if to :
    Code:
    if &notnbacktrialcount == 15 || $memory == 1 && &trialcount > 2 && &nbacktrialcount < 10
    And I increased the two variables accordingly.

    I hope you understood the different changes I made.