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

Can we compare Enums with strings or another way?

Asked by
Xianon 105
8 years ago

I did a sistematic combat system, it iterares all over looking for the attack by the specified key. Turns out i can't compare Enums with strings or their repective values from the Wiki. If i can't compare it this way then i would have to define the event for each attack and that would be overkill.

plyInput.InputBegan:connect(function(input, validInput)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local currentPlayerAbilities = plyAbilities:GetChildren()
        for i = 1, #currentPlayerAbilities do
            print(currentPlayerAbilities[i].Name)
            print(currentPlayerAbilities[i].Value)
            if currentPlayerAbilities[i].Value == input.KeyCode then
                local currentGameAbilities = Abilities:GetChildren()
                for i = 1, #currentGameAbilities do
                    if currentGameAbilities[i].Key.Value == input.KeyCode then
                        local chosenAbility = currentGameAbilities[i]
                        local output = chosenAbility.BaseDamage.Value + plyStats.Strenght.Value
                        local attackAnimation = plyChar.Humanoid:LoadAnimation(chosenAbility.Animation)
                        attackAnimation:Play()
                        AttackingState = true
                    end
                end
            end
        end
    end
end)

1 answer

Log in to vote
1
Answered by 8 years ago

Enum value's have a Name property you can query to compare to strings i.e. print("Slate" == Enum.Material.Slate.Name)

In your case, you would use currentGameAbilities[i].Key.Value == input.KeyCode.Name

Ad

Answer this question