So I’ve been racking my brain trying to figure out how to implement a “talk” function in my game. I’m new to C# programming but I’ve been doing as much reading and experimenting as I can with the language.
This is what I have so far:
Comm comm = new Comm();
string message = null;
if (InputBox.Text == "say " + message)
{
OutputBox.AppendText(comm.do_say(message));
}
class Comm
{
public string do_say(string message)
{
return "You say: " + message + "\n";
}
}
Now, this doesn’t work. I think I know why, but I can’t seem to figure out just how to redo it so it does work… I’ve tried to replace:
(InputBox.Text == "say " + message)
with
(InputBox.Text == "say {0}", message)
and it doesn’t work either. So, now I’m out of ideas on how to make this work. I tried searching stackoverflow and google for answers but came up with nothing.
Any help or hints on how to fix it would be great!
Thanks.
You don’t know what the
messageis in advance, right? You need to search for the “Say “, and take the rest of the string as input.SubString(4)will return whatever’s after the first 4 characters in the string, everything after the"Say "