Overview
This prompt provides a Lua script for spawning pets in the Adopt Me game, enhancing user experience. Programmers and game developers will benefit from the code’s structure and validation features.
Prompt Overview
Purpose: This Lua script facilitates pet spawning in the Adopt Me game with user-friendly validation.
Audience: The intended users are game developers and programmers working on the Adopt Me game.
Distinctive Feature: It includes a Levenshtein Distance function for suggesting similar pet names based on user input.
Outcome: Users can spawn pets accurately while receiving helpful suggestions for invalid inputs.
Quick Specs
- Media: Code
- Use case: Pet spawning in games
- Techniques: Levenshtein Distance, Input validation
- Models: Lua
- Estimated time: 1 hour
- Skill level: Intermediate
Variables to Fill
- [string.lower(pet)] – String.lower(pet)
- [i] – I
- [0] – 0
- [j] – J
- [i-1] – I 1
- [j-1] – J 1
- [len_s] – Len S
- [len_t] – Len T
- [normalizedInput] – Normalizedinput
Example Variables Block
- [string.lower(pet)]: dog
- [i]: 1
- [j]: 2
- [j-1]: 1
- [len_s]: 3
- [len_t]: 4
- [normalizedInput]: cat
The Prompt
“`lua
— Lua script for Adopt Me game:
— Spawn a pet from a predefined list with validation and suggestions
— 1. Define a list of valid pet names
local validPets = {
“Dog”,
“Cat”,
“Dragon”,
“Unicorn”,
“Turtle”,
“Penguin”,
“Horse”,
“Frog”,
“Wolf”,
“Rabbit”
}
— 2. Create a lowercase lookup table for validation
local petLookup = {}
for _, pet in ipairs(validPets) do
petLookup[string.lower(pet)] = pet
end
— 3. Helper: convert string to lowercase
local function toLower(str)
return string.lower(str or “”)
end
— 4. Levenshtein Distance function
local function levenshtein(s, t)
local len_s = #s
local len_t = #t
if len_s == 0 then return len_t end
if len_t == 0 then return len_s end
local matrix = {}
— Initialize matrix
for i = 0, len_s do
matrix[i] = [[0] = i]
end
for j = 0, len_t do
matrix[0][j] = j
end
for i = 1, len_s do
for j = 1, len_t do
local cost = (s:sub(i,i) == t:sub(j,j)) and 0 or 1
matrix[i][j] = math.min(
matrix[i-1][j] + 1, — deletion
matrix[i][j-1] + 1, — insertion
matrix[i-1][j-1] + cost — substitution
)
end
end
return matrix[len_s][len_t]
end
— 5. Suggest pet names close to invalid input
local function suggestPets(input, maxDistance)
local suggestions = {}
for _, pet in ipairs(validPets) do
local dist = levenshtein(toLower(input), toLower(pet))
if dist
Screenshot Examples
How to Use This Prompt
- validPets: List of valid pet names.
- petLookup: Lowercase lookup table for validation.
- toLower: Function to convert strings to lowercase.
- levenshtein: Calculates distance between two strings.
- suggestPets: Suggests pet names based on input.
- spawnPet: Function to spawn a pet via API.
- userInput: Input from user for pet name.
- normalizedInput: Lowercase version of user input.
Tips for Best Results
- Input Validation: Always validate user input to prevent errors.
- Use Lookup Tables: Optimize searches with lowercase lookup tables for quick validation.
- Levenshtein Distance: Implement this algorithm for suggesting similar names to users.
- Feedback Loop: Provide clear feedback and suggestions for invalid inputs to enhance user experience.
FAQ
- What is the purpose of the validPets list?
It defines the names of pets that can be spawned in the game. - How does the script validate pet names?
It uses a lowercase lookup table to check if the input matches valid pet names. - What is the Levenshtein Distance function used for?
It calculates the difference between two strings to suggest similar pet names. - What happens if an invalid pet name is entered?
The script suggests similar valid pet names based on the input.
Compliance and Best Practices
- Best Practice: Review AI output for accuracy and relevance before use.
- Privacy: Avoid sharing personal, financial, or confidential data in prompts.
- Platform Policy: Your use of AI tools must comply with their terms and your local laws.
Revision History
- Version 1.0 (February 2026): Initial release.


