I need help with the timer function

I am having problems with NRPN messages being sent to fast to a synth. I need to slow this process down so I was hoping to put a 2ms pause between each line of code. @Balint suggested to accomplish thos “the basics of it would be a timer start on the triggering event that puts the value of the triggering element in a FIFO buffer that has it’s own retrigger until empty.” I have no idea where to start with this. The synth is expecting 6 seperate lines of code(4 xCC’s and 2 resets). I have figured out the messages that need to be sent but I can’t figure how to pause in between lines for a brief period of time. Any help would be appreciated
.

hi!

This is something I came up with. This is an iteration over the defined nrpn_cc_arr with the help of timer event re-triggers.

Setup Event:

-- Iterator variable used by the Timer event, needs to be initialised
self.c = 0

Button Event:

-- Start the timer on button press
if self:button_state() > 0 then
    timer_start(self:element_index(), 1)
end

Timer Event:

-- I have added your MIDI values to an array from the discord, only the param1 and param2 parts
nrpn_cc_arr = {{99, 1}, {98, 108}, {6, 0}, {38, 0}, {101, 127}, {100, 127}}

-- Increment variable every time timer get's hit
self.c = self.c + 1

-- Your channel for the MIDI messages, could be typed directly in midi_send() as well.
local ch = 0

-- This is a trick to use less characters, we reassign a value to a new local variable
local _ = nrpn_cc_arr[self.c]

-- Send the MIDI data when this timer runs
midi_send(ch, 176, _[1], _[2])

-- Restart this very same timer with 100 frame delay, make it higher or less depending on your requirement
timer_start(self:element_index(), 100)

-- The array nrpn_cc_arr has 6 elements. Once we are ready iterating over it to send out the full delayed MIDI message, reset the self.c variable to 0 and stop the timer 
if self.c == 6 then
  self.c = 0
  timer_stop(self:element_index())
end