Hi Wake–I thought I’d get back to you that I finally make things work both online and offline, though it took a few days! I tried a lot tips you and others shared about the movie but nothing worked. It turned out that I just needed to set the movie duration to be three decimals in the condition file…I will post my final codes below in case other people can benefit from it. Thank you so much for all your help.
For the current demo:
- Subjects rate their emotions on a 0-100 scale (from “very negative” to “very positive”) while viewing movie clips.
- The slider marker can be moved by simply moving the mouse within the area of the slider (without clicking).
- Each trial ends when the video ends.
- Continuous ratings (every 3 frame) can be saved along with the rating time.
- The slider marker starts at the end position of a previous trial.
Note: To make the exp work properly, you need to add a mouse component named “mouse” in the first routine.
For code_JS (set code type to be JS for running online):
# Begin Experiment
thisExp=psychoJS.experiment;
win=psychoJS.window;
event=psychoJS.eventManager;
shuffle = util.shuffle;
Array.prototype.append = [].push;
For codeOnlineRating:
# Begin Experiment
# Change the following parameters according to your own exp
slider_width = 1
slider_height = .05
slider_orientation = 0
#Failing to set ticks or labels in code
slider_ticks=[0, 100]
slider_labels=['Very positive','Very negative']
slider_granularity = .1
slider_decimals = 1
slideSpeed = 3
oldRating = 50
# Begin Routine
if slider_granularity == 0:
slider_granularity = .1
# frame counter
thisFrame = 0
# create an empty list to store data
slider_data=[]
# set start position of the slider to end position of the previous trial
slider.markerPos = oldRating
# record the current position of the mouse
mouseRec=mouse.getPos()
# Each Frame
# Create a slider_shape in this routine with the same size as the slider
# Check if mouse is moving within slider_shape, if so change marker position accordingly
if slider_shape.contains(mouse) and mouse.getPos()[slider_orientation] != mouseRec[slider_orientation]:
mouseRec = mouse.getPos()
slider.markerPos = mouseRec[slider_orientation]/slider_width*(slider_ticks[-1]-slider_ticks[0])+(slider_ticks[0]+slider_ticks[-1])/2
# update oldRatings if
if slider.markerPos:
if oldRating != slider.markerPos:
oldRating = slider.markerPos
# for now slideSpeed = 3, so ratings and time saved for every 3 frame
thisFrame += 1
if slider.markerPos and thisFrame%slideSpeed==0:
slider_data.append([round(oldRating,slider_decimals),int(t*1000)])
# End Routine
# save continous ratins to the data file
thisExp.addData('All Responses',slider_data)
#thisExp.addData('Final Response',round(slider.markerPos,slider.decimals))
print('All Responses',slider_data)
#print('Final Response',round(slider.markerPos,slider.decimals))