I have a chat box in my game and I would like to be able to make it so that it can recognize specific commands from the player. I already have it so that you can enter to start the command, and I know I can use if command == "whatever command I want", but how would I recognize specific words in a string? Like /tp in minecraft teleportation? Thanks in advance!
1 - Check the first character for your command string (/) if(command[0] == "/") and remove the command character. 2 - Tokenize the String (stringsplit on spacebar or other) 3 - Switch on command[1] 4 - implement your case statements (via delegates or other command handler methods) Give this a try. If you cannot get it to work, I will post some code later.
Um, sorry for the double post, but it seems string.Split is not working well. Code (csharp): var command : String[]; command = textField.Split(" ", [0]); EDIT: It says No appropriate version of 'String.Split' for the argument list '(String, int[])' was found. EDIT... AGAIN: Fixed! Thanks joshimoo, works perfectly! It had to be " " [0] with no comma!