Question

I'm making a steam trading bot, and I want to be able to fetch my inventory and send it to the other user, this is what I've done (using SteamKit2):

dynamic Response;
string Inv;
string name = Bot.SteamFriends.GetFriendPersonaName(OtherSID);
System.Console.WriteLine(name + " Said: " + message);
Response = Inventory.GetInventory(Bot.SteamClient.SteamID);
System.Console.WriteLine(Inv = Response.rgInventory);
Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, Inv);

I get the following error:

[TF2 Bot 2014-04-25 20:13:18] ERROR: Microsoft.CSharp.RuntimeBinder.RuntimeBinde
rException: Cannot implicitly convert type 'Newtonsoft.Json.Linq.JArray' to 'str
ing'. An explicit conversion exists (are you missing a cast?)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T
0 arg0)
at SteamBot.SimpleUserHandler.OnMessage(String message, EChatEntryType type)
in C:\Users\Raka Gunarto\Documents\GitHub\SteamBot\SteamBot\UserHandler.cs:line
47
at SteamBot.Bot.<HandleSteamMessage>b__8(FriendMsgCallback callback) in C:\Us
ers\Raka Gunarto\Documents\GitHub\SteamBot\SteamBot\Bot.cs:line 481
at SteamKit2.CallbackMsg.Handle[T](Action`1 handler)
at SteamBot.Bot.HandleSteamMessage(CallbackMsg msg) in C:\Users\Raka Gunarto\
Documents\GitHub\SteamBot\SteamBot\Bot.cs:line 471
at SteamBot.Bot.BackgroundWorkerOnDoWork(Object sender, DoWorkEventArgs doWor
kEventArgs) in C:\Users\Raka Gunarto\Documents\GitHub\SteamBot\SteamBot\Bot.cs:l
ine 731

So my question is: How do you convert JArray to String? If just do Response.rgInventory in System.Console.WriteLine, it's fine. But when I try to send someone a message, it's not fine because the SendChatMessage Function accepts a string as an input.

Was it helpful?

Solution

Depending on the implementation, you should be able to use:

Inv = Response.rgInventory.toString();

If this does not lead to a satisfying result, you might have to construct the string yourself. You can always go ahead and override the toString() method as well to make it fit your demands.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top