Search Unity

error CS1503

Discussion in 'Getting Started' started by re_e, Apr 15, 2021.

  1. re_e

    re_e

    Joined:
    Apr 12, 2021
    Posts:
    4
    Hello!
    I recently started programming and got this error message while trying to make a dialogue.
    I know that the problem comes from the type "string" of my variable but I don't know how to do otherwise
    here are the two codes:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [System.Serializable]
    6. public class dialogue
    7. {
    8.     [TextArea(3, 10)]
    9.     public string [] sentences;
    10. }

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class dialoguetriggerNPC1 : MonoBehaviour
    6. {
    7.     public bool cantalk;
    8.     public dialogue dialogue;
    9.  
    10.  
    11.     private void Update()
    12.     {
    13.         if (cantalk && Input.GetKeyDown(KeyCode.E))
    14.         {
    15.             TriggerDialogue();
    16.         }
    17.     }
    18.     private void OnTriggerEnter(Collider Collision)
    19.     {
    20.         if (Collision.CompareTag("Player"))
    21.         {
    22.             cantalk = true;
    23.         }
    24.     }
    25.  
    26.     private void OnTriggerExit(Collider collision)
    27.     {
    28.         if (collision.CompareTag("Player"))
    29.         {
    30.             cantalk = false;
    31.         }
    32.     }
    33.  
    34.     void TriggerDialogue()
    35.     {
    36.         FindObjectOfType<dialogueManager>().StartDialogue(dialogue);
    37.     }
    38. }
    the error is at the end of the second script, in void TriggerDialogue, and more precisely in (dialogue)

    thank you in advance!
    and sorry if my english is bad
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    What is the error message?
     
  3. re_e

    re_e

    Joined:
    Apr 12, 2021
    Posts:
    4
    it's :
    error CS1503: Argument 1: cannot convert from 'dialogue' to 'dialogueManager'
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    I'm assuming then the
    StartDialogue
    method is mistakenly asking for a
    dialogueManager
    parameter, rather than a
    dialogue
    parameter that you're giving it.
     
    re_e likes this.
  5. re_e

    re_e

    Joined:
    Apr 12, 2021
    Posts:
    4
    it works! thank you so much
     
    Vryken likes this.
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    For future note, no one memorizes error codes. The error message you posted in comment #3 is very helpful, but just as helpful is the set of numbers in parenthesis that immediately follows the error message, as well as the name of the script the error occurs.

    The script file name is important, so we're looking at the correct file for the error. But the numbers in parenthesis go with that, where the 1st number is the line number the error occurs. All that info together lets anyone go exactly to the line in the code the compiler believes the error occurs. The actual problem is either on that line, or very close to it. Providing all that info just makes it really easy to help for anyone, and it doesn't cost you much extra time to provide. Just so you know, and you can use it yourself too for your own investigation. Good luck with your project.
     
    Vryken likes this.
  7. re_e

    re_e

    Joined:
    Apr 12, 2021
    Posts:
    4
    thank you, I will remember it!
     
    Joe-Censored likes this.