Lua Scripting Error for Dota 2

没有其他地方能够帮助我,所以我来这里希望有人能帮助我解决我在Dota2的Lua脚本中遇到的问题

以下是我的错误代码:

function ApplyDamage(keys)

local caster = keys.caster
local ability = keys.ability
local target = keys.target

ability.level = ability:GetLevel() - 1

local ability_dmg = ability:GetLevelSpecialValueFor (“damage”, ability.level)

if caster:HasScepter()then
    ability_dmg = ability:GetSpecialValueFor(“damage_scepter”,ability.level)
end

ApplyDamage({victim = target,attacker = caster,damage = ability_dmg,damage_type = ability:GetAbilityDamageType()})

end

这会返回以下错误:

https://i.stack.imgur.com/KDtrg.png

我弄不清楚为什么会这样以及如何解决。请帮忙。

点赞
用户2420301
用户2420301

你的代码本身并没有问题。但你传递的参数中的“keys”并不包含“ability”键。你必须检查调用的地方,而不是函数本身。

2017-05-07 08:31:50
用户5287638
用户5287638

问题是你把你的函数命名为"ApplyDamage",这就覆盖了 DOTA 全局的 ApplyDamage 函数。然后当你在函数内部调用 ApplyDamage 时,实际上你是在调用你刚刚定义的函数,而不是你原本想要调用的全局函数。相反,你应该使用一个 DOTA 没有使用过的名称,例如 damageTarget

local function damageTarget(keys)
    local caster = keys.caster
    local ability = keys.ability
    local target = keys.target

    ability.level = ability:GetLevel() - 1

    local ability_dmg = ability:GetLevelSpecialValueFor(
        "damage",
        ability.level
    )

    if caster:HasScepter() then
        ability_dmg = ability:GetSpecialValueFor(
            "damage_scepter",
            ability.level
        )
    end

    ApplyDamage{
        victim = target,
        attacker = caster,
        damage = ability_dmg,
        damage_type = ability:GetAbilityDamageType()
    }
end
2017-05-07 12:27:16