Module:Sandbox/LVL: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 54: Line 54:
     if(hero == nil) then return "Hero Not Found" end
     if(hero == nil) then return "Hero Not Found" end
      
      
     -- Check top-level first, then Weapon, then AltFire
     local var_value
    local var_value = hero[hero_stat_key]
 
    if var_value == nil and hero.Weapon then
    -- Special handling for WeaponName and WeaponDescription which use different keys in the JSON data
         var_value = hero.Weapon[hero_stat_key]
    if hero_stat_key == "WeaponName" then
        if hero.Weapon and hero.Weapon.NameKey then
            var_value = hero.Weapon.NameKey
        end
    elseif hero_stat_key == "WeaponDescription" then
        if hero.Weapon and hero.Weapon.DescKey then
            var_value = hero.Weapon.DescKey
        end
    else
        -- Default logic for other stats
        -- Check top-level first, then Weapon, then AltFire
        var_value = hero[hero_stat_key]
        if var_value == nil and hero.Weapon then
            var_value = hero.Weapon[hero_stat_key]
         end
        if var_value == nil and hero.Weapon and hero.Weapon.AltFire then
            var_value = hero.Weapon.AltFire[hero_stat_key]
        end
     end
     end
     if var_value == nil and hero.Weapon and hero.Weapon.AltFire then
   
         var_value = hero.Weapon.AltFire[hero_stat_key]
     if(var_value == nil) then
        -- For string-based values like names/descriptions, return an empty string if not found.
        if hero_stat_key == "WeaponName" or hero_stat_key == "WeaponDescription" then
            return ""
        end
         -- For numeric stats, return 0 as the default.
        return 0
     end
     end
   
    if(var_value == nil) then return 0 end
      
      
     --round
     --round