Help in setting action to "pick random entry"

95 views
Skip to first unread message

Plutoxoxo

unread,
Jul 17, 2023, 1:34:40 AM7/17/23
to mementodatabase
hi everyone, i'm new to this app and have little to no knowledge in JavaScript.
what I'd like to do is: when i'm in my music library (which contains albums, mixtapes, extended plays... etc) is to somehow let it pick a random entry from all entries (albums, mixtapes...) and i figured that this is what actions are for? if anyone can help me set this up please! thanks in advance! and sorry for the inconvenience.

Bill Crews

unread,
Jul 17, 2023, 2:26:46 AM7/17/23
to Plutoxoxo, mementodatabase, Vasiliy Egorov
Interesting problem. In a JavaScript library action script, all the entries in the library are read into an array (like a list, but numbered 0 to maximim - 1 instead of 1 to maximum). If you could generate a random integer such that 0 <= number < # of entries, you could do it. So, how to do that? Well, as you can read at...


..., there is a method (a function) that will return a real number between 0 & 1. So, to scale that to the number of entries in your library and simultaneously make the number an integer (so you can use it to select an entry), you can use a function like this in your code...

function getRandomInteger(max) {
    return Math.floor(Math.random() * max);
}

So, start with that and then write the rest of your script...

let entries = lib().entries();
let numberOfEntries = entries.length;
let selection =
    getRandomInteger(numberOfEntries);
let e = entries[selection];
// Put code to show this entry here

So, you'd bring up the entries list for your Music library and press the action button (looks like a YouTube Play button near the top of the screen).

But, to bring that entry up on the screen, there used to be a function called show(e) that would display the entry in an entry view card, but some of us have found that that function no longer exists or works. It did exist and work back when I documented it in the wiki. We'd need to ask the developer about that...

Sup...@MementoDatabase.com

So, we've identified the intended entry, but I don't know how to select that entry as the current entry.

So, developer, we have the entry in the variable e. Now how do we make that be the current entry and show it? Does show(e) or lib().show(e) exist? How does it work? It apparently no longer works as documented in the wiki.



On Mon, Jul 17, 2023, 1:34 AM Plutoxoxo <walid...@gmail.com> wrote:
hi everyone, i'm new to this app and have little to no knowledge in JavaScript.
what I'd like to do is: when i'm in my music library (which contains albums, mixtapes, extended plays... etc) is to somehow let it pick a random entry from all entries (albums, mixtapes...) and i figured that this is what actions are for? if anyone can help me set this up please! thanks in advance! and sorry for the inconvenience.

--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/609b4c5b-6eb8-4cb4-a580-497e9603cdcen%40googlegroups.com.

Er Mo

unread,
Jul 17, 2023, 1:28:15 PM7/17/23
to mementodatabase
Hallo Bill
Ich würde das mit der Anzeige so machen : Ein Feld in die Bibliothek Name " Suche "  einbauen und einen Filter auf diese Feld . Mit den Skript wird der Wert auf 1 gesetzt und wenn der Wert 1 ist Zeigt der Filter den Eintrag an

Hello Bill
I would do it like this with the display: Install a field in the library name "Search" and a filter on this field. With the script the value is set to 1 and if the value is 1 the filter shows the entry

Ernst

Bill Crews

unread,
Jul 17, 2023, 1:48:07 PM7/17/23
to Er Mo, mementodatabase
Ich verstehe nicht.  Filter zeigen keine Einträge an, könnten die Liste jedoch auf einen Eintrag beschränken.
__________

I don't understand. Filters don't show entries, though it could limit the list to one entry.


Er Mo

unread,
Jul 17, 2023, 2:46:44 PM7/17/23
to mementodatabase
Hallo Bill
Ja angezeigt wird der Eintrag nicht , aber man muss nur auf den Einzigen Eintrag klicken um die Daten zu sehen oder die Ansicht auf Tabelle stellen . Habe mahl einen Kleine Test gemacht

Hello Bill
Yes, the entry is not displayed, but you only have to click on the single entry to see the data or set the view to table. I did a little test


Ernst
Reply all
Reply to author
Forward
0 new messages