Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[SOLVED] CS1503 C# Argument 2: cannot convert from 'string' to 'bool'

Discussion in 'Scripting' started by Gam_Write12, Oct 16, 2019.

  1. Gam_Write12

    Gam_Write12

    Joined:
    Oct 16, 2019
    Posts:
    3
    Hello!
    I'm trying to make my first visual novel and following the tutorial while learning the coding and the like.
    Right now I'm stuck in the character management where character starts the dialogue.

    The code is bellow (which I didnt write myself but followed the video, here is the link
    )
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. [System.Serializable]
    7. public class Character
    8. {
    9.     public string characterName;
    10.  
    11.     [HideInInspector] public RectTransform root;
    12.  
    13.     public bool isMultiLayerCharacter { get { return renderers.renderer == null; } }
    14.  
    15.  
    16.     DialogueSystem dialogue;
    17.     public void Say(string speech)
    18.     {
    19.         dialogue.Say(speech, characterName);
    20.      
    21.     }
    22.     public Character (string _name)
    23.     {
    24.         CharacterManager cm = CharacterManager.instance;
    25.         GameObject prefab = Resources.Load("Characters/Character[" + _name + "]") as GameObject;
    26.         GameObject ob = GameObject.Instantiate(prefab, cm.characterPanel);
    27.  
    28.         root = ob.GetComponent<RectTransform>();
    29.         characterName = _name;
    30.  
    31.         renderers.renderer = ob.GetComponentInChildren<RawImage>();
    32.         if (isMultiLayerCharacter)
    33.             {
    34.             renderers.bodyRenderer = ob.transform.Find("bodyLayer").GetComponent<Image>();
    35.             }
    36.  
    37.         dialogue = DialogueSystem.instance;
    38.     }
    39.  
    40.     [System.Serializable]
    41.     public class Renderers
    42.     {
    43.         public RawImage renderer;
    44.         public Image bodyRenderer;
    45.         public Image expressionRenderer;
    46.     }
    47.  
    48.     public Renderers renderers = new Renderers();
    49. }
    50.  
    Before I had everything working just fine Thanks to Stellar Studio (link to his channel: https://youtube.com/channel/UCWNe1O8SukKMUYKI6qLuFHw) but this is the problem I ran into :(
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Please copy the entire error message, and tell us which line in your code the error corresponds to.
     
  3. Gam_Write12

    Gam_Write12

    Joined:
    Oct 16, 2019
    Posts:
    3
    I think it's somewhere around
    1. public void Say(string speech)
    2. {
    3. dialogue.Say(speech, characterName);
    4. }
    because when I double click on my error it highlits characterName there and error itself says Argument 2: cannot convert from 'string' to 'bool'
    this is how it looks in my visual studio program:
     

    Attached Files:

  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    The function "Say" in DialogueSystem takes different parameters than what you've put in there, but without seeing what DialogueSystem has we can't really say what it should be. Look at the definition of the "Say" function and see which parameter is incorrect.
     
    Gam_Write12 likes this.
  5. Gam_Write12

    Gam_Write12

    Joined:
    Oct 16, 2019
    Posts:
    3
    Oh thank you I did check in my DialogueSystem script and noticed that I wrote bool additive = false in public void Say so I deleted it and error was gone. I also got error in another script but I didn't need that one because i already have characterTesting script where dialoogue is scripted too so I just commented the whole script. Now everything is working.

    THANK YOU SO MUCH!
    I know it's small achievement but I still appreciate it!
     
  6. HiddenMatrix

    HiddenMatrix

    Joined:
    Dec 9, 2018
    Posts:
    8


    i have the same issue
    but don't exactly know what you changed, any help would be appreciated
     

    Attached Files:

  7. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    well first of all: always give your full error message

    second: look at the error message, it details exactly where the error is (which script in which line in which column)
    using this information isolate the faulty code and only post where the error actually lies, dont post all your scripts
    for syntax errors like this it is almost always sufficent to only look at the line the error message points to, and the line befor and after that

    third: the meaning of your error message is simply that you are trying to convert a text into a truth value, so simply look at the line givin to you by the error message and think about which varibles or functions are returning a text and which ones are expecting a bool
     
  8. HiddenMatrix

    HiddenMatrix

    Joined:
    Dec 9, 2018
    Posts:
    8
    seriously what's the problem, I wasn't duplicating my post, i was replying to the guy who had the same problem i'm currently experiencing in the little hope he might respond, so that would be continuing this post's thread, people don't need to be so hard on me with their tone of comments, i'm just a beginner coder, trying to find help/advise from a community to help me learn and improve, i'm having a bad day, in general anyway, so i don't see why people have to be so frustrated with how someone approaches a problem their trying to get help with.
     
  9. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    well I didnt see your other thread so I assumed you were just having some "cannot convert from 'string' to 'bool'" error, and not literally the exact same issue and code as talked about in this post

    the issue in this thread was that DialogueSystem only defines a function "Say" that takes at least a string and a bool, but OP tried to give it only 2 strings as parameters

    in other words, you are trying to do something with the function DialogueSystem.Say which it wasnt designed for

    the awkward thing about attaching cs files instead of posting code with the code tags is that anyone who wants to help you has to download your code

    I have downloaded your code and in your DialogueSystem class you define your Say function as:

    Code (CSharp):
    1.  
    2.     public void Say(string speech, bool v, string speaker = "")
    3.     {
    4.         StopSpeaking();
    5.  
    6.         speaking = StartCoroutine(Speaking(speech, false, speaker));
    7.     }
    thus it takes a string, a bool and an optional string in that order
    yet you only call Say on 2 strings, speech and characterName, the way you defined the function it would have to be something like
    Code (CSharp):
    1. dialogue.Say(speech, someBool, characterName);
    the someBool here is some truth value (true or false) though since I didnt look further through your code, I dont know what exactly you want here

    the reason why ppl might seem frustrated is because it is hard to help someone who doesnt understand the syntax of the code they need help with
    it is really important to understand what error messages are trying to tell you and for that you will need to understand c# syntax first