#weird repeating print statement

12 messages · Page 1 of 1 (latest)

tame niche
#

for some reason i have a function that prints the correct output and then prints again resulting in an empty table. (check the attached photo for the output)

#

this is the function responsible for the error

#
local function decideOptions()
    local randomNumRed = math.random(1, #characterList)
    local randomNumBlue = math.random(1, #characterList)
    local choices = {}
    if randomNumRed == randomNumBlue then
        decideOptions()
    else
        for i, v in pairs(characterList) do
            if i == randomNumRed or randomNumBlue then
                table.insert(choices, v)
            end
        end
    end
    print(choices)
    return choices
end
random anchor
#

also your if statement is a bit off

#

if i == randNumRed or i == randNumBlue then

tame niche
random anchor
#

did u fix your if statments

#

also how many characters are in characterslist?

#

if its just 1 then both of the random numbers are always gonna be 1 because theres no other number they can return with only 1 character in the list and your 1st if statement checks if both numbers equal each other, it runs the function again and then in that function the same thing happens creating a loop that crashes your game

tame niche
#

@random anchor theres 2 characters for that reason