Hi all,
I am trying to create a routine that shows a 10px*100px square and will then grow horizontally upon a keypress.
I can do this just find in the builder-only routine by setting the size to: (10*(t*5),0)
, but I cannot figure out the analog to have this occur in a code-snippet and be initialized by a keypress.
I have tried to have a code snippet with the following text:
if 'left' in keys():
sq.width = sq.width*(t*5)
That returns an error that t
is not defined, which I know understand. However, I tried to implement the same type of idea using the component name and that just grows the square on each press.
if 'left' in keys:
sq.width = sq.width*(sq.tStart*10)
I think the cleanest way is the first method using the builder component, but is there a way to delay the presentation or progression of any size change until a key has been pressed?
Thank you for your time!
The easiest thing to do is split the task across two consecutive routines. Have the keypress force the end of the first routine. Then have the square on the second routine, set to grow automatically just by putting that (10*(t*5), 0)
expression in its size field. This removes the need for a code component all together.
That is probably just because the code was in the wrong tab - t
doesn’t start counting up until the start of the routine, so it can’t be in the “begin experiment” tab, for example.
Thank you, Michael!
That works perfectly in Builder, but when I upload it to Pavlovia to pilot I am getting two errors:
- Before the second square starts to grow, the entire screen turns black for a brief moment.
- Whatever size the square is stopped at becomes an after image on the next trial.
For example, if I press space when the square is 100px across, there will be a brief image of the 100px square before it begins to grow from the start.
I have tried to put sq.width=.01
in the End Routine
component but then it forces a loop where the square won’t grow on the next trial.
The experiment is public, I use Pavlovia on a credit basis so I’m not sure if you can see it directly.
Thank you for your time!
No apologies needed! I appreciate the feedback you have given and will consider making a new post as it seems we have solved the original issue.