C# I have a Steam swap bot and it returns the error "Undefined object reference to an instance of an object"

Asked

Viewed 792 times

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?

  • You’re right there’s a difference between bot and Bot-- probably, one is an instance of the class Bot, and the other is the class Bot if. The function NewTradeOffer() is static? If it is, Bot.NewTradeOffer that’s right.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.