Posted 31 March 2013 - 04:33 AM
Hello,
I have made a shuffle function but the problem that I am havind that it doesnt always assign a value to tCoords.value. I have no clue why it does that and thats why I am here. I need this for my upcoming game memory!
The code:
I hope you guys can help me with this. This is probably the most important part of memory.
For those who like pastebin: http://pastebin.com/y3B56RT7
Thanks in advance for helping me,
Engineer
Edit: Solved
I have made a shuffle function but the problem that I am havind that it doesnt always assign a value to tCoords.value. I have no clue why it does that and thats why I am here. I need this for my upcoming game memory!
The code:
local shuffle = function()
for i = 1, 28 do
tCoords[i].active = false
end -- To set the 'cards' showing = false
local tempValStorage = {} -- check if I already have that number
local randomVal -- So everything stays local
for i = 1, 14 do -- 14 sets of numbers
while true do
randomVal = math.random(1, 14)
local redeem = true
for i = 1, #tempValStorage do
if tempValStorage[i] == randomVal then -- Checking if I already have that number
redeem = false
break
end
end
if redeem then
table.insert(tempValStorage, randomVal)
break
end
end
while true do
local randomIndex = math.random(1, 28) -- generate for wich buttons
local randomIndex2 = math.random(1, 28)
if not tCoords[randomIndex].value and not tCoords[randomIndex2].value then -- check if they dont have a value
tCoords[randomIndex].value = randomVal -- set the number
tCoords[randomIndex2].value = randomVal
break
end
end
end
return true
end
I hope you guys can help me with this. This is probably the most important part of memory.
For those who like pastebin: http://pastebin.com/y3B56RT7
Thanks in advance for helping me,
Engineer
Edit: Solved