3
I searched all the other topics and saw several answers but I can’t apply them to my application because I don’t know anything about C#... My site is CS:GO betting and I have a C# bot that works as normally as it should (when you complete the amount of items in the betting pot it makes the draw) but I need it to also activate when the time is up for depositing skins. So I just took the command he executes when the pot gets full and pasted in the part where time runs out.
The command that works(parts of it) is this:
namespace SteamBot
{
public class DepositTradeOfferUserHandler : UserHandler
{
public DepositTradeOfferUserHandler(bot bot, SteamID sid) : base(bot, sid) { }
...
...
...
BotInventory botInventory = JsonConvert.DeserializeObject<BotInventory> (botInvString);
if (botInventory.success != true) {
Log.Error ("An error occured while fetching the bot's inventory.");
return;
}
var rgInventory = botInventory.rgInventory;
//Create trade offer for the winner
var winnerTradeOffer = Bot.NewTradeOffer (winnerSteamID);
This part works perfectly... Now the part I created that is activated when time runs out and the draw is held:
Task f = Task.Factory.StartNew(() =>
{
int count = 1;
while (count <= 1)
{
...
...
...
var rgInventory = botInventory.rgInventory;
//Create trade offer for the winner
var winnerTradeOffer = bot.NewTradeOffer(winnerSteamID);
//Loop through all winner's items and add them to trade
List<long> alreadyAddedToWinnerTrade = new List<long>();
Note that it is the same command but in this second block the code does not work.
Error message: CS0120 C# An object reference is required for the non-static field, method, or property 'bot.NewTradeOffer(SteamID)'
I know it must be something simple, but I don’t know anything about C# and I really need your help, thank you. If you need any more code or explanation, just say the word. Thanks in advance!
EDIT: I noticed that the two codes were not similar so I renamed "bot" to "bot" to look like this, and now the error message is this: CS0236 C# A field initializer cannot reference the non-static field, method, or property 'UserHandler.Bot'
This error is occurring in this line var winnerTradeOffer = bot.Newtradeoffer(winnerSteamID); from the part you copied and pasted?
– Erick Gallani
You’re right there’s a difference between
bot
andBot
-- probably, one is an instance of the classBot
, and the other is the classBot
if. The functionNewTradeOffer()
isstatic
? If it is,Bot.NewTradeOffer
that’s right.– brazilianldsjaguar