This is a part of my code. Help please. Rrror CS1503: Argument `#1' cannot convert `string' expression to type `int'. But how? I should to compare row with player name.
[DOUBLEPOST=1454616634,1454599677][/DOUBLEPOST]Please help. I need this urgently.Code:string query; query = string.Format("SELECT `steamid`, `user` FROM `{0}` WHERE `clan` = '{1}' LIMIT 1", dbConnection["Table"], ClanName); _mySql.Query(Sql.Builder.Append(query), _mySqlConnection, (List<Dictionary<string, object>> row) => { var playerslist = new List<string> {string.Empty}; foreach (var players in GameManager.Instance.GetSessions()) { object user = row["user"]; var tplayer = players.Value; var compare = String.Equals(tplayer.Name, user); if (!tplayer.IsLoaded) continue; if (compare == false) continue;
Cannot convert `string' expression to type `int'
Discussion in 'Hurtworld Development' started by DJDiamonD, Feb 4, 2016.
-
Wulf Community Admin
You can't compare a string with an int, you'll need to either case or use ToString() where your int is. The issue is with your String.Equals.
-
-
I don't know C#, but:
Code:var compare = String.Equals(tplayer.Name, user.ToString());
-
-
At what line is the error?
-
I tryied string, int, ToString(). Nothing doesn't work -
-
[DOUBLEPOST=1454756762][/DOUBLEPOST]
Maybe here is saying? I don't know so good.
[DOUBLEPOST=1454834581,1454756718][/DOUBLEPOST]UP
[DOUBLEPOST=1454943415][/DOUBLEPOST]Anybody will help? -
object user = row["user"];
to
var user = row["user"];
It is hard to help if we do not have more info, like what data does user have? Is it a username? -
[DOUBLEPOST=1455176750][/DOUBLEPOST]
PrintWarning(row.GetType().ToString()); -
@LaserHydra I suggested the var because tostring doesn't work on an object, or am I mistaken?
[DOUBLEPOST=1455177094][/DOUBLEPOST]and if the error really is on that row, it's omplaining that it can't make a string into an object. eother way more info is needed to help the guy -
Last edited by a moderator: Feb 11, 2016
-
- Query(Sql sql, Connection db, Action<List<Dictionary<string, object>>> callback) where db is the variable you create with OpenDb() and sql is created by NewSql
-
-
Code:void ClanMembers(object ClanName, PlayerSession player, ulong steamID) { string query; query = string.Format("SELECT `steamid`, `user` FROM `{0}` WHERE `clan` = '{1}' LIMIT 1", dbConnection["Table"], ClanName); _mySql.Query(Sql.Builder.Append(query), _mySqlConnection, (List<Dictionary<string, object>> row) => { var playerslist = new List<string> {string.Empty}; foreach (var players in GameManager.Instance.GetSessions()) { object user = row["user"]; var target = players.Value; var compare = String.Equals(target.Name, user); if (!target.IsLoaded) continue; if (compare == false) continue; if (playerslist[playerslist.Count - 1].Length + target.Name.Length > 50) playerslist.Add(string.Empty); if (playerslist[playerslist.Count - 1] != string.Empty) playerslist[playerslist.Count - 1] += ", "; playerslist[playerslist.Count - 1] += $"<color=green>{target.Name}</color>"; } if (playerslist[playerslist.Count - 1] != string.Empty) foreach(var msg in playerslist) hurt.SendChatMessage(player, msg); else hurt.SendChatMessage(player, "Offline"); }); }
-
from what hydra said, you will have to loop the users if you want to find them all. Since a clan can contain multiple users.
example:
foreach (var user in row)
{
}