[solved] Strange error from pattern_time

When I use pattern_time in a script on my norns to record button press on my grid, and then try to play them back, the first time I play the pattern back, I get this error in maiden:

.//home/we/norns/lua/lib/pattern_time.lua:111: attempt to perform arithmetic on a nil value (field '?')
stack traceback:
	.//home/we/norns/lua/lib/pattern_time.lua:111: in function '/home/we/norns/lua/lib/pattern_time.next_event'
	.//home/we/norns/lua/lib/pattern_time.lua:20: in field 'event'
	/home/we/norns/lua/core/metro.lua:169: in function </home/we/norns/lua/core/metro.lua:166>

Does anyone have an idea what I’m doing wrong?
I just do something like

pattern:start()

After I record the pattern with pattern:rec_start().

I have used pattern_time before, with no problems, but I can’t see what I’m doing wrong now to give me this error.

Hard to say without seeing your code. Are you setting pattern = pattern_time.new()?

If you look at line 111 in pattern_time.lua where the error is thrown, it looks like either self.time or self.time_factor are nil, and these are only set on the table when you initialize pattern_time with pattern_time.new()

edit: also, I think you have to call rec_stop() before you can call start(), in case you aren’t already doing this

Thanks, that helped me to find the problem… It was in my script!
I never sent the pattern.rec_stop(). So self.time was probably nil, because it hadn’t stopped recording yet, when I was trying to play it back.
It was all due to a small mislabeling of a variable… Gotta look close!

2 Likes