Filtered self-updating random items

BACKGROUND

In the below doc, on the Guitar Chord Trainer page, each time the Update (btn_UpdateChord) button is clicked, it updates the txt_CurrentItem text control with a random item from the Chords table (see the Data page). The button uses the RandomItem() formula to do this.

QUESTIONS

1. Filtered items

How can I get the RandomItem() formula to only include the Chords table’s filtered items, rather than all its items?

(I’ve managed to filter the actual Chords table the way I want - with an interactive filter based on the mlt_SelectedNotes and mlt_SelectedVariations multiple select controls (see the Guitar Chord Trainer page). However, it doesn’t alter the behaviour of the RandomItem() formula that uses the table as its input.)

2. Alternative trigger

Is there a way I can get the random items that appear in the txt_CurrentItem text control updated via some sort of timer, instead of via the user clicking the btn_UpdateChord button?

The idea would be to create something like this Countdown timer with action in the end. But, instead, when the countdown gets to zero:

  1. The txt_CurrentItem text control is updated with a new random item, AND
  2. The countdown restarts (i.e. it cycles through continuously until interrupted).

Then there could be another button to cancel/end the countdown.

Hi Andrew!

The answer to your first question is simple, but not necessarily obvious: You must create a separate filtered view of Chords and plug that view into your formula, instead of the table itself.

Why? because RandomItem([some table]) may return any item from the table (regardless of any filters applied) while RandomItem([view of table]) can only return an item this is shown in [view of table].

For your second question, there is no way I know of to get Coda to trigger an action more than once per hour, except there is a tricky workaround. Check out this example doc:

Let me know if you need an explanation of what’s going on here :slightly_smiling_face:

Wow. Thanks Ryan.

You’re absolutely right. The filter solution is very simple, but it wasn’t obvious to me. (Now that you’ve explained it though, it makes good sense.)

I’ll play around with your Random Items in Turn example. While I don’t fully understand it (yet), I think I’m across enough of it to hopefully steal from your solution :slight_smile:.

Thanks so much for your help.

1 Like