As per Wakefield's Daily Tips - #100 by wakecarter you should focus on what is undefined. In your case I think it’s trialIndex. Try putting print('trialIndex',trialIndex)
on line 3.
I haven’t had any experience with .getFutureTrial, so I suspect that that’s the issue. It could be simply that you need to remove the quotes from around “n”. I’ll report back here if I get a chance to investigate.