Attempt to index global 'keys' (a nil value)

edited September 2015 in Questions

KV

"wukong_echo_sweep"
{
    "BaseClass"                     "ability_datadriven" 
    "AbilityBehavior"               "DOTA_ABILITY_BEHAVIOR_NO_TARGET"
    "AbilityUnitTargetTeam"         "DOTA_UNIT_TARGET_TEAM_ENEMY"
    "AbilityUnitTargetType"         "DOTA_UNIT_TARGET_HERO | DOTA_UNIT_TARGET_BASIC"
    "AbilityUnitDamageType"         "DAMAGE_TYPE_PURE"
    "AbilityTextureName"            "phantom_lancer_spirit_lance"
    "AbilityCooldown"               "12.0 11.0 10.0 9.0"
    "AbilityManaCost"               "90"

    "AbilitySpecial"
    {
        "01"
        {
            "var_type"                  "FIELD_INTEGER"
            "damage"                    "100 150 200 250"
        }
        "02"
        {
            "var_type"                  "FIELD_FLOAT"
            "area_of_effect"            "350"
        }
        "03"
        {
            "var_type"                  "FIELD_INTEGER"
            "illusion_damage_out_pct"   "-77 -77 -77 -77"
        }
        "06"
        {
            "var_type"                  "FIELD_INTEGER"
            "tooltip_illusion_damage"   "33"
        }
        "07"
        {
            "var_type"                  "FIELD_INTEGER"
            "illusion_damage_in_pct"    "0.01 0.01 0.01 0.01"
        }
        "08"
        {
            "var_type"                  "FIELD_INTEGER"
            "tooltip_illusion_total_damage_in_pct"  "0.01 0.01 0.01 0.01"
        }           
        "09"
        {
            "var_type"                  "FIELD_INTEGER"
            "illudur"                   "2"
        }
    }
    "OnSpellStart"
    {
        "ActOnTargets"
        {
            "Target"
            {
                "Center" "CASTER"
                "Radius" "%area_of_effect"
                "Teams" "DOTA_UNIT_TARGET_TEAM_ENEMY" 
                "Types" "DOTA_UNIT_TARGET_BASIC | DOTA_UNIT_TARGET_HERO"
            }
            "Action"
            {
                "TrackingProjectile"
                {
                    "Target" "TARGET"
                    "EffectName" "particles/units/heroes/hero_enchantress/enchantress_impetus.vpcf"
                    "Dodgeable" "1"
                    "ProvidesVision" "1"
                    "VisionRadius" "300"
                    "MoveSpeed" "1000"
                    "SourceAttachment" "DOTA_PROJECTILE_ATTACHMENT_ATTACK_1"
                }
            }
        }
    }
    "OnProjectileHitUnit"
    {
        "DeleteOnHit"   "1"
        "Damage"
        {
            "Type"          "DAMAGE_TYPE_MAGICAL"
            "Damage"        "%damage"
            "Target"        "TARGET"
        }
        "RunScript"
        {
            "ScriptFile"            "scripts/vscripts/abilities/wukong.lua"
            "Function"              "WukongQ"
        }
    }
}

LUA

function WukongQ( event )
  local caster = event.caster
  local player = caster:GetPlayerID()
  local ability = event.ability
  local unit_name = caster:GetUnitName()
  local duration = caster:GetAttacksPerSecond()
  local outgoingDamage = ability:GetLevelSpecialValueFor("illusion_damage_out_pct", ability:GetLevel()-1)
  local incomingDamage = ability:GetLevelSpecialValueFor("illusion_damage_in_pct", ability:GetLevel()-1)
  local target = keys.target

  local illusion = CreateUnitByName(unit_name, target, true, caster, nil, caster:GetTeamNumber())
  illusion:SetPlayerID(caster:GetPlayerID())

  local casterLevel = caster:GetLevel()
  for i=1,casterLevel-1 do
    illusion:HeroLevelUp(false)
  end

  illusion:SetAbilityPoints(0)
  for abilitySlot=0,15 do
    local ability = caster:GetAbilityByIndex(abilitySlot)
    if ability ~= nil then 
     local abilityLevel = ability:GetLevel()
     local abilityName = ability:GetAbilityName()
     local illusionAbility = illusion:FindAbilityByName(abilityName)
     illusionAbility:SetLevel(abilityLevel)
    end
  end

  for itemSlot=0,5 do
    local item = caster:GetItemInSlot(itemSlot)
    if item ~= nil then
      local itemName = item:GetName()
      local newItem = CreateItem(itemName, illusion, illusion)
      illusion:AddItem(newItem)
    end
  end

  illusion:AddNewModifier(caster, ability, "modifier_illusion", { duration = duration, outgoing_damage = outgoingDamage, incoming_damage = incomingDamage })

  illusion:MakeIllusion()

  illusion:PerformAttack(target, true, true, true, true)
end

How can I fix this?

How can i fix this? The ability only deals damage but does not summon illusion.

Comments

  • Change

    local target = keys.target
    

    to

    local target = event.target
    

    keys is undefined in the function, so lua tries to find the global variable "keys", but cannot find it, since it hasn't been defined either. That's why you get the message.

  • Okay, now it works. Thank you so much.

  • LOL in DOTA custom games. aaaaah :-) like it kinda :-D

  • edited September 2015 Posts: 14

    @megamanxcc I did not know that there is this kind of ability in LoL. I am working on Gamemode on normal dota map but with new heroes, and i am trying to make Sun Wukong.