Reputation: 1
I have been trying to build the following Text Adventure and have reached an error that I cannot figure out how to resolve. The error is:
Assets/My_Scripts/MH_Script.cs(19,23): error CS1501: No overload for method Add' takes 2' arguments
Here is the beginning code for MH_Script.cs
, the list is rather long since this is a Text Adventure.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MH_Script {
public static List<MH_ScriptManager> sList = new List<MH_ScriptManager>();
public MH_Script(){
sList.Add("start", "You awaken in a sweltering room....
There are more strings added to sList
in the same manner followed by:
public string SendScript(string state){
string returnthis = "";
foreach(MH_ScriptManager sm in sList){
if(sm.getState() == state){
returnthis = sm.getStory();
}
}
return returnthis;
}
}
and here is MH_ScriptManager
:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MH_ScriptManager{
public Helpers.STATE gState;
public string gScript;
public string getCurrentState(){
return gState;
}
public MH_ScriptManager (string state, string script){
gState = Helpers.ParseEnum<Helpers.STATE>(state);
gScript = script;
}
public string getStory(){
return gScript;
}
public string getState(){
return gState.ToString();
}
public void setStory(string script){
gScript = script;
}
public void setState(string state){
gState = Helpers.ParseEnum<Helpers.STATE>(state);
}
public bool compareStatetoString(string compare){
if (gState == Helpers.ParseEnum<Helpers.STATE> (compare))
return true;
else
return false;
}
}
Can somebody please explain to me what I am doing wrong, and how I can go about resolving this error in the future?
Upvotes: 0
Views: 100
Reputation: 16956
List.Add
takes single argument, but in this case you are passing two arguments, which is causing an exception.
Also sList
is of type MH_ScriptManager
, so what you need is
sList.Add(new MH_ScriptManager("start", "You awaken in a sweltering room..."));
Upvotes: 3
Reputation: 2255
Because Add
method should have one argument but you give it two arguments, so
sList.Add("start", "You awaken in a sweltering room);
change to:
sList.Add("You awaken in a sweltering room)
Upvotes: 2