Description of the problem: I tried building a slider that would could be controlled via the keyboard based on the interactive slider by Wakefield Morys-Carter (Pavlovia).
I tweaked a few things based on my experiement, e.g. chaning ticks marks and response keys and removing the mouse component. This works perfectly offline.
In the online version, the experiment the slider is shown, but:
irrespective of which key i use it always moved once to the right
after the initial move, i cannot move it anymore
the single key press moved it further along the scale than in the offline version
If anyone has some ideas i would more very grateful
thanks for your response! here are the changes i made:
in addition ot changes in the code component below, i also removed the ‘trial’ and ‘gap’ routines, which didn’t seem problematic offline.
in the ‘iSlider’ routine, the ‘iSlider_code’ component (set to Auto → JS) under the ‘Begin Routine’ tab i changed the keysWatched variable and commented out the ‘mouseRec’ variable:
keysWatched=['w', 'p', 'return']
in the each frame routine this is the code as it is currently (the mouse and ‘text_data’ elements are commented out):
if thisFrame == 0:
for tick in ticks:
tick.setAutoDraw(True)
thisFrame += 1
# End routine with keyboard
if newRating > -999 and status[2] == 'down':
continueRoutine=False
# End routine with mouse
#elif newRating > -999 and mouse.isPressedIn(marker):
#continueRoutine=False
# Move slider with keyboard
elif status[0] == 'down':
sliding = -slider_granularity
elif status[1] == 'down':
sliding = slider_granularity
# Move slider with mouse
#elif slider_background.contains(mouse) and mouse.getPos()[slider_orientation] != mouseRec[slider_orientation]:
#mouseRec=mouse.getPos()
#newRating = round((mouseRec[0]/slider_width*(slider_ticks[-1]-slider_ticks[0])+(slider_ticks[0]+slider_ticks[-1])/2),slider_decimals)
#sliding = 0
# Do nothing
else:
sliding = 0
# Change rating using keyboard
if sliding != 0 and thisFrame%slideSpeed == 0:
# Allocate midpoint if first interaction is keyboard
if newRating == -999:
newRating = round((slider_ticks[0]+slider_ticks[-1])/2,slider_decimals)
else:
newRating = round(newRating+sliding,slider_decimals)
# Check newRating is in range
if newRating > slider_ticks[-1]:
newRating=slider_ticks[-1]
elif newRating > -999 and newRating < slider_ticks[0]:
newRating=slider_ticks[0]
#Update slider text and marker if needed
if oldRating != newRating:
#slider_text.text = str(newRating)
oldRating = newRating
marker.setPos([slider_width*(newRating-(slider_ticks[0]+slider_ticks[-1])/2)/4,0])
if newRating>-999 and thisFrame%slideSpeed==0:
slider_data.append([round(oldRating,slider_decimals),int(t*1000)])
# text_data.setPos(.5,len(slider_data)*.1-.4)
additionally, and probably not relevant, i also changed the labels, ticks, speed, and marker colour in the silder set up (set to Auto → JS):
slider_width=1
slider_height=.05
slider_orientation=0
#Failing to set ticks or labels in code
slider_ticks=[1,20]
#slider_labels
slider_labels=['Positive','Negaitve']
slider_granularity=.01
slider_decimals=3
sliding = 0
slideSpeed = 1
oldRating=-1
marker_colour='black'
marker_size=.03
sliderColour='LightGray'