#Returned Table being different than the assigned Table for some reason.
1 messages · Page 1 of 1 (latest)
Code:
local PossibleQuestNames = {"Hits","Kills","Blocks","PerfectBlocks","PerfectBlockStreak","BlockBreaks"}
local function ChooseRandomNumbers(NumA, NumB) --Num stands for Number
task.wait(0.01)
local Numbers = {math.random(NumA, NumB), math.random(NumA, NumB), math.random(NumA, NumB)}
for Index, Number in pairs(Numbers) do
print(Number)
end
if Numbers[1] == Numbers[2] or Numbers[1] == Numbers[3] or Numbers[2] == Numbers[3] or Numbers[2] == Numbers[1] then
print("Same Number detected")
ChooseRandomNumbers(NumA, NumB)
end
return Numbers
end
local function ChooseQuests()
local QuestNames = {}
task.wait(0.01)
local Numbers = ChooseRandomNumbers(1,3)
print("| Number Choosing done |")
for Index, Number in pairs(Numbers) do
print(Number)
table.insert(QuestNames, PossibleQuestNames[Number])
end
print("| Quest Choosing done |")
for Index, QuestName in pairs(QuestNames) do
print(QuestName)
end
end
Video Footage
Extra screenshot of the code
well when a number is the same (which you can really check so much easier) you're just calling the function again but not doing anything with what it returns
so wait. Does that mean that the Table i assign in the ChooseQuest function has always the values of the first ChooseRandomNumbers function Table?
yes
because that call just calls the function itself and creates a new one completely different but that table is not used
also the check can be really easy to do like this:
local function isValueRepeatedInTable(table: {[any]: any}): boolean
local seen = {}
for _, v in table do
if seen[v] then
return true
end
seen[v] = true
end
return false
end
and just do if isValueRepeatedInTable(t) do...
wait but if the function i call will always be a new one how can i repeat the function until isValueRepeatedInTable() == false?
just do return funcCall() in the if
here
return ChooseRandomNumbers(NumA, NumB)
aaa i see
thank you for helping. Btw what does this syntax mean? I have never seen the "(table: {[any]: any}): boolean"
that's type annotation, basically it's like a guide with what types are you working and what types are you returning, for more info: https://luau.org/typecheck
A fast, small, safe, gradually typed embeddable scripting language derived from Lua