0
I’m trying to develop a code in my game but I’m making this mistake.
...
case "cpsuser":
Console.Write("Digite o apelido do usuário: ");
string Nickname = Console.ReadLine();
Console.Write("Digite a quantidade de Cupons");
string Cupons = Console.ReadLine();
Console.Write("Digite a mensagem a ser informada para o player. Por exemplo: Parabéns você recebeu 10000 Cupons.");
string Message = Console.ReadLine();
GamePlayer Player = WorldMgr.GetAllPlayers()
.FirstOrDefault(p => p.PlayerCharacter
.NickName == Nickname);
if (Player == null)
{
Console.WriteLine("O usuário informado não existe ou está offline!");
}
else
{
int num6 = (object)Cupons;
foreach (GamePlayer gamePlayer in WorldMgr.GetAllPlayers())
{
gamePlayer.AddMoney(num6);
gamePlayer.SendMessage("({0})", Message);
}
}
break;
...
In case this is where I’m wrong:
...
else
{
int num6 = (object)Cupons;
foreach (GamePlayer gamePlayer in WorldMgr.GetAllPlayers())
{
gamePlayer.AddMoney(num6);
gamePlayer.SendMessage("({0})", Message);
...
You’re trying to put an Object inside an int. Imagine that Object is the father of all objects, and int is the son of Object, in an analogy you are trying to put the father inside the child.
– Guilherme Guini
How could I try to fix?
– user39571
use Convert.Toint32, it has to be an object that can be converted to int, for example a string or a decimal. What does this coupons object have of property? What type is it?
– Guilherme Guini
Already solved thank you.
– user39571
@Vinicius actually was not solved, I gave an answer because the answers they had teach wrong.
– Maniero