Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Error CS7036: There is no argument given that corresponds to the required formal parameter

Discussion in 'Scripting' started by GameDev_A, Jan 26, 2023.

  1. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    43
    Hi, while I was programming I got this error: error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'Dictionary<Stat, int>.Add(Stat, int).
    I tried to fix it, but I couldn't, could someone help me? thank you.

    Here's the code(Visual studio reports the error on lines 48 to 52):

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [System.Serializable]
    6. public class Pokémon
    7. {
    8.     [SerializeField] PokémonBase _base;
    9.     [SerializeField] int level;
    10.  
    11.     public PokémonBase Base {
    12.         get
    13.         {
    14.             return _base;
    15.         }
    16.     }
    17.     public int Level
    18.     {
    19.         get
    20.         {
    21.             return level;
    22.         }
    23.     }
    24.  
    25.     public int HP { get; set; }
    26.     public List<Move> Moves { get; set; }
    27.     public Dictionary<Stat, int> Stats { get; private set; }
    28.     public Dictionary<Stat, int> StatBoosts { get; private set; }
    29.  
    30.     public void Init()
    31.     {
    32.         //Generate Moves
    33.         Moves = new List<Move>();
    34.         foreach (var move in Base.LearnableMoves)
    35.         {
    36.             if (move.Level <= Level)
    37.                 Moves.Add(new Move(move.Base));
    38.  
    39.             if (Moves.Count >= 4)
    40.                 break;
    41.         }
    42.  
    43.         CalculateStats();
    44.         HP = MaxHp;
    45.  
    46.         StatBoosts = new Dictionary<Stat, int>()
    47.         {
    48.             (Stat.Attack, 0),
    49.             (Stat.Defense, 0),
    50.             (Stat.SpAttack, 0),
    51.             (Stat.SpDefense, 0),
    52.             (Stat.Speed, 0)
    53.         };
    54.     }
    55.  
    56.     void CalculateStats()
    57.     {
    58.         Stats = new Dictionary<Stat, int>();
    59.         Stats.Add(Stat.Attack, Mathf.FloorToInt((Base.Attack * level) / 100f + 5));
    60.         Stats.Add(Stat.Defense, Mathf.FloorToInt((Base.Defense * level) / 100f + 5));
    61.         Stats.Add(Stat.SpAttack, Mathf.FloorToInt((Base.SpAttack * level) / 100f + 5));
    62.         Stats.Add(Stat.SpDefense, Mathf.FloorToInt((Base.SpDefense * level) / 100f + 5));
    63.         Stats.Add(Stat.Speed, Mathf.FloorToInt((Base.Speed * level) / 100f + 5));
    64.  
    65.         MaxHp = Mathf.FloorToInt((Base.Speed * Level) / 100f) + 10;
    66.     }
    67.  
    68.     int GetStat(Stat stat)
    69.     {
    70.         int statVal = Stats[stat];
    71.  
    72.         //applty stat boost
    73.         int boosts = StatBoosts[stat];
    74.         var boostValues = new float[] { 1f, 1.5f, 2f, 2.5f, 3f, 3.5f, 4f };
    75.  
    76.         if (boosts >= 0)
    77.             statVal = Mathf.FloorToInt(statVal * boostValues[boosts]);
    78.         else
    79.             statVal = Mathf.FloorToInt(statVal / boostValues[boosts]);
    80.  
    81.         return statVal;
    82.     }
    83.  
    84.     public int Attack
    85.     {
    86.         get { return GetStat(Stat.Attack); }
    87.     }
    88.  
    89.     public int Defense
    90.     {
    91.         get { return GetStat(Stat.Defense); }
    92.     }
    93.  
    94.     public int SpAttack
    95.     {
    96.         get { return GetStat(Stat.SpAttack); }
    97.     }
    98.  
    99.     public int SpDefense
    100.     {
    101.         get { return GetStat(Stat.SpDefense); }
    102.     }
    103.  
    104.     public int Speed
    105.     {
    106.         get { return GetStat(Stat.Speed); }
    107.     }
    108.  
    109.     public int MaxHp
    110.     {
    111.         get; private set;
    112.     }
    113.  
    114.     public DamageDetails TakeDamage(Move move, Pokémon attacker)
    115.     {
    116.         float critical = 1f;
    117.         if (Random.value * 100f < 6.25f)
    118.             critical = 2f;
    119.  
    120.         float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);
    121.  
    122.         var damageDetails = new DamageDetails()
    123.         {
    124.             TypeEffectiveness = type,
    125.             Critical = critical,
    126.             Fainted = false
    127.         };
    128.  
    129.         float attack = (move.Base.Category == MoveCategory.Speciale) ? attacker.SpAttack : attacker.Attack;
    130.         float defense = (move.Base.Category == MoveCategory.Speciale) ? SpDefense : Defense;
    131.  
    132.         float modifiers = Random.Range(0.85f, 1f) * type * critical;
    133.         float a = (2 * attacker.Level + 10) / 250f;
    134.         float d = a * move.Base.Power * ((float)attack / defense) + 2;
    135.         int damage = Mathf.FloorToInt(d * modifiers);
    136.  
    137.         HP -= damage;
    138.         if(HP <= 0)
    139.         {
    140.             HP = 0;
    141.             damageDetails.Fainted = true;
    142.         }
    143.  
    144.         return damageDetails;
    145.     }
    146.  
    147.     public Move GetRandomMove()
    148.     {
    149.         int r = Random.Range(0, Moves.Count);
    150.         return Moves[r];
    151.     }
    152. }
    153.  
    154. public class DamageDetails
    155. {
    156.     public bool Fainted { get; set; }
    157.     public float Critical { get; set; }
    158.     public float TypeEffectiveness { get; set; }
    159. }
     
    Last edited: Jan 26, 2023
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,931
    The correct way to write the Ditionary initializer is:

    Code (CSharp):
    1.         StatBoosts = new Dictionary<Stat, int>()
    2.         {
    3.             {Stat.Attack, 0},
    4.             {Stat.Defense, 0},
    5.             {Stat.SpAttack, 0},
    6.             {Stat.SpDefense, 0},
    7.             {Stat.Speed, 0}
    8.         };
    You used () instead of the correct {}
     
    GameDev_A and Bunny83 like this.
  3. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,103
    Well, this:
    should be this
    Code (CSharp):
    1.         StatBoosts = new Dictionary<Stat, int>()
    2.         {
    3.             {Stat.Attack, 0},
    4.             {Stat.Defense, 0},
    5.             {Stat.SpAttack, 0},
    6.             {Stat.SpDefense, 0},
    7.             {Stat.Speed, 0}
    8.         };
     
    GameDev_A likes this.
  4. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    43
    Thanks for the correction
     
  5. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    43
    Thanks, tomorrow I'll correct the code