When you assign a function to event, it will be called at every single step and whatever it returns will be the value at that step. The context.step value tells you what step you are on.
In your first two example you assigned a pure sequence, just in the second case you’ve used a function to generate it at the time of assignment, this is different from assigning a function itself (where it is up to pattrns to call it later).
Not sure what you expect as output here though. Do you want to play one sequence after another, take notes from two sequences alternating between which one to take from, or something else?
You’ll probably have to manage looking up a specific step from a sequence table inside your function.
For example the script below plays sequence a at the beginning then just repeats b indefinitely. Note how inside the function we are returning a single element from the lists using the the .step value on the context (c here) to derive the index.
Also using math.imod to have a wrapping index (as % would give us zero when wrapping around).
local a = {"c3", "a#3", "d3", "f3"}
local b = {"g2", "g3"}
return pattern {
unit = "1/8",
event = function(c)
if c.step <= #a then
return a[c.step]
else
return b[math.imod(c.step,#b)]
end
end
}
That’s not how it behaves because the function is called every step. As I explained above, when using functions you will have to implement the logic you want on a per-step basis. The engine expects a single step to come out of the function so if you return a list of notes, it will interpret it as a chord.
Your particular pattern could be written like this
return pattern {
unit = "1/8",
event = function(c)
if math.imod(c.step, 2) == 1 then
return "c4"
else
if math.imod(c.step, 4) == 2 then
return "off d0.3"
else
return "off d0.1"
end
end
end
}
But obviously this kind of logic can get hard to manage fast so you might want to keep track of where different sequences are at with your own variables and so on, depending on what else you want to do later.
Or you might want to write a function that calculates an entire sequence ahead of time and give the result of that to event.
You could also use the cycle notation where expressing alternating events is simpler