well in the api it did said that swear=1 = swear words and swear=0 = no swear words but lets give it a shot!
welp now what i have in mind is to make it get all the words and select a few words from it and also the lesser the chars the lesser the complexity (in my case)
Welp @regexman looks like I have found the code…
local HttpService = game:GetService("HttpService")
local NumOfWords = 3
local Complexity = 5
local function GenerateWord(len)
local url = "https://random-word-api.herokuapp.com/all"
local response = HttpService:GetAsync(url)
local decoded = HttpService:JSONDecode(response)
local totalwords = {}
local gottenwords = 0
repeat
local w = decoded[math.random(1,#decoded)]
if string.len(w) <= Complexity then
gottenwords += 1
table.insert(totalwords,w)
end
wait()
until gottenwords == len
return totalwords
end
local Words = {}
Words.WordTable = GenerateWord(NumOfWords)
return Words
its slow but works I mean the words are hard but still easy
local HttpService = game:GetService("HttpService")
local NumOfWords = 3
local Complexity = 3
local function GenerateWord(len)
local url = "https://random-word-api.herokuapp.com/all"
local response = HttpService:GetAsync(url)
local decoded = HttpService:JSONDecode(response)
local totalwords = {}
local gottenwords = 0
for i,v in pairs(decoded) do
local w = decoded[math.random(1,#decoded)]
if string.len(w) <= Complexity then
gottenwords += 1
table.insert(totalwords,w)
end
if gottenwords == len then
break
end
end
return totalwords
end
local Words = {}
Words.WordTable = GenerateWord(NumOfWords)
return Words
faster but laggier
Ok, you should also filter it with Roblox.
hmm yes i forgot about that parts. Thanks for giving me a base to work on!
also thanks for the script for less complex words!! it gonna help cuz I wanna make a small game off it
well welcome then doe it kinda still gives complex words but not that complex words
ik, it’s gonna be some challenge lol
yes it is probably need to detect if the words starts or includes or ends with a specific letter
Similar to what you’re trying to achieve.
I found a list of “friendly” words which should prove useful to you, here’s the script I wrote.
local http = game:GetService("HttpService")
local randomObject = Random.new(tick())
local url = "https://raw.githubusercontent.com/glitchdotcom/friendly-words/master/words/objects.txt"
local wordTable = {}
local function sendHttpRequest()
local success, result = pcall(function()
return http:GetAsync(url)
end)
if success then
if result then
for word in result:gmatch("%a+") do
table.insert(wordTable, word)
end
end
else
warn(result)
end
end
sendHttpRequest()
local function getRandomWord()
local randomInt = randomObject:NextInteger(1, #wordTable)
return wordTable[randomInt]
end
It’d be better to just issue the HTTP request once, collect a set of words in a table value and then get random words from this table when necessary instead of issuing a HTTP request each time a new random word is needed. Here’s a sample of 20 randomly generated words.
wow I didnt knew that you can also use github! thanks I will surely look on to using your code
I completely agree, what if you sent a http request and the players finished it quickly, you will need to quickly get another word instead of trying to respect the ratelimits
to be honest i think my and geometricalC2123’s code is a bit better
Not really, you need to wrap the HTTP request inside a pcall otherwise if the HTTP request drops (fails) the script will error resulting in its premature termination.
sorry what? i kinda get it but also dont get it
yea i know that
local HttpService = game:GetService("HttpService")
local url = "https://random-word-api.herokuapp.com/all"
local response = HttpService:GetAsync(url)
local decoded = HttpService:JSONDecode(response)
local function GenerateWord(C,len)
local totalwords = {}
local gottenwords = 0
for i,v in pairs(decoded) do
local w = decoded[math.random(1,#decoded)]
if string.len(w) <= C then
gottenwords += 1
table.insert(totalwords,w)
end
if gottenwords == len then
break
end
end
return totalwords
end
local Words = {}
function Words:GenWords(Complexity,Length)
return GenerateWord(Complexity,Length)
end
return Words
so I made it a bit better
As I said before, filter it with Roblox