Tracks Module
Overview
This script is a module that manages a collection of tracks, providing various functionalities such as retrieving tracks, searching for tracks, and more. It also contains helper functions for advanced and fuzzy searching.
Services
MarketplaceService: Used to fetch product information, specifically for audio assets.
Data Structures
tracks: A table containing a list of tracks. Each track has anid,title, andartist.
Functions
getSoundInfo(soundId):Description: Fetches the sound information from the Roblox marketplace.
Parameters:
soundId(string): The ID of the sound.
Returns: A table containing the sound's information if successful, otherwise
nil.
Tracks.GetTracks():Description: Retrieves all tracks.
Returns: A table containing all tracks.
Tracks.GetTrack(index):Description: Retrieves a specific track by its index.
Parameters:
index(number): The index of the track in thetrackstable.
Returns: The track at the specified index.
Tracks.GetTrackById(id):Description: Retrieves a track by its ID.
Parameters:
id(string): The ID of the track.
Returns: The track with the specified ID or
nilif not found.
Tracks.GetNextTrack(currentTrackId):Description: Retrieves the next track after the specified track ID.
Parameters:
currentTrackId(string): The ID of the current track.
Returns: The next track or
nilif the current track ID is not found.
Tracks.search(title, artist):Description: Searches for tracks based on title and/or artist using fuzzy search.
Parameters:
title(string, optional): The title of the track.artist(string, optional): The artist of the track.
Returns: A table containing the search results.
levenshteinDistance(str1, str2):Description: Calculates the Levenshtein distance between two strings.
Parameters:
str1(string): The first string.str2(string): The second string.
Returns: The Levenshtein distance between the two strings.
advancedSearch(tbl, kvs):Description: Performs an advanced search on a table based on key-value pairs.
Parameters:
tbl(table): The table to search.kvs(table): The key-value pairs to search for.
Returns: An iterator function for the search results.
fuzzySearch(tbl, kvs, threshold):Description: Performs a fuzzy search on a table based on key-value pairs and a threshold.
Parameters:
tbl(table): The table to search.kvs(table): The key-value pairs to search for.threshold(number): The maximum Levenshtein distance for a match.
Returns: An iterator function for the search results.
Usage
To use this module in another script:
Notes
The
getSoundInfofunction fetches sound information from the Roblox marketplace. It checks if the asset type is audio and if the name is not a removed copyright track.The
levenshteinDistancefunction is a helper function used to calculate the minimum number of single-character edits required to change one string into another.The
advancedSearchandfuzzySearchfunctions are utility functions for searching within thetrackstable. ThefuzzySearchfunction uses the Levenshtein distance to determine the similarity between strings.
Last updated