Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

If statement being skipped, why?

Asked by 1 year ago
Edited 1 year ago
local List = {1,50,9,6,4,91,125}
local RequiredSurvivors = 3
local IterationsCompleted = 0
local IterationsRequired = 5

--print(#List)


local function NewDescendant(i)

    local Ancestor = List[i]
    local Descendant = Ancestor + math.random(-5,5)
    print(Descendant)

    table.insert(List,Descendant)
end




local function genset(List)


    if not IterationsRequired == IterationsCompleted then

        print("Setting Up New Gen.")
        for i = 1,#List do
            NewDescendant(i)
        end
        RunGen()
    end
end

function RunGen()
    for i = 1,#List do
        wait(0.125)
        local NumToRemove = math.min(table.unpack(List))
        print(NumToRemove)
        table.remove(List,table.find(List,NumToRemove))
        if #List == RequiredSurvivors then
            print(List)
            RequiredSurvivors = RequiredSurvivors + 1
            IterationsCompleted = IterationsCompleted + 1
            print("Generation Completed.")
            genset(List)

            break
        end
    end
end




RunGen()

Im trying to make a number based evolution system but im having trouble with a if statement being skipped and i need assistance. The if statement is line 24 - 31

1 answer

Log in to vote
1
Answered by
AZDev 590 Moderation Voter
1 year ago
Edited 1 year ago

It's been a while but I'll try to explain this as well as I can.


-- lets make this slightly simpler. if not 1==1 then end -- this literally translates to if not true then --do stuff end


if not 1==2 then end -- this literally translates to if not false then end

Your if statement can never do anything because the conditions cannot be satisfied.

Instead, to check if a number is or isn't equal to something you should simply use the operators.


--is equal to if 1 == 1 then is equal to end if 1 ~= 1 then not equal to end
Ad

Answer this question