Cannot convert `BasePlayer[]' expression to type `string[]'Solved

Get this error:

Error while compiling: GodAddEvent.cs(41,65): error CS1503: Argument `#2' cannot co
nvert `BasePlayer[]' expression to type `string[]'

        [ChatCommand("godAdd")]
        void cmdGodadd (BasePlayer player, string command, string[] args)
        {
            string name = " ";
            foreach(string arg in args)
            {
                name = name + " " + arg;
            }
            var playerlist = BasePlayer.activePlayerList;
            var target = BasePlayer.Find(name);
            if(target == null)
            {
                string namesList = string.Join(", ", playerlist.ToArray());
                string list = string.Concat(" ", namesList);
                SendReply(player, "The list of the players avaliable is this: ");
                SendReply(player, list);
            }
        }

 

You're trying to convert an array of objects to a string array, you'd need to get the names (or whatever actual string you want) from the list before trying to join as one string.

Sorry for the question wulf, but can you tell me how I can get the names before using the string.Join?

How can I convert an activePlayerList to names in string

Oh, I changed the following line:

string namesList = string.Join(", ", playerlist.ToArray());

to

string namesList = string.Join(", ", playerlist.Select(p => p.displayName.Sanitize()).ToArray());
Locked automatically