What am I trying to do?
Currently, I’m trying to make a math.random
script that doesn’t repeat any number it’s already generated.
Script
local TableDemo = {}
local Table2 = {1,2,3,4,5,6,7,8,9,10}
while true do
local Num = math.random(1,10)
print(Num)
if table.find(TableDemo, Num) then
wait()
print('NotAdded')
if TableDemo == Table2 then --Issue
print('Cleared')
table.clear(TableDemo)
end
elseif not table.find(TableDemo, Num) then
table.insert(TableDemo, Num)
print('Added'..Num)
wait(0.5)
end
end
Issues
The main issue is just my lack of knowledge on these things.
Where I put --Issue
is where the issue is.
Everything else works, but the main issue is just the checking of if TableDemo
is equal to Table2
.
All the script does is loop print numbers that weren’t added (numbers already in the list) when the list is done.
My question
Is there any way to check TableDemo
's values and to see if it’s 1-10 so I can reset it?
All I need is an answer above and the solution for this issue.
What I think is wrong
If you know what’s wrong feel free to not read this. Or correct me if you want.
I think I’m getting issues because the numbers are inputted randomly into TableDemo
and Table2
is organized.
(E.g. TableDemo
probably looks something like {3,4,9,8,2,10,1,7,5,6}
and Table2
is just set 1-10 according to value.)
Solutions I’ve tried
I’ve looked around on DevForum and the ways to do this look complicated to me and hard to understand.
I’m just trying to create something I can personally understand.
I could probably create a way to check TableDemo
by going number by number, but I’m looking for a solution that’s less line intensive.