0

I have problem, i have coded some simple if statement on beggining of the code that looks like this:

    manager.on('sentOfferChanged', function(offer, oldState) {
 if (TradeOfferManager.ETradeOfferState[offer.state] === "Declined") {
  var ifvartruefalse = false;
  return;
} if (offer.itemsToGive.length == 0){
    if (offer.state == TradeOfferManager.ETradeOfferState.Accepted){
     var ifvartruefalse = true;
    }
  }
});

Then I am trying to call that var from these if statements to tell me if its true or false inside another if statement:

                                                    if (ifvartruefalse == false){
                                                    message.reply('<:false:750799883572609245> **Trade was declined, deleting the coinflip**');
                                                    return
                                                  }

                                                    if (ifvartruefalse == true){
                                                    message.channel.send('<:true:750799921497505913> **Trade was succesfully confirmed**, generating random ticket from 0 to 100');

And keep getting error that ifvartruefalse is not defined. Please someone help...

  • A declaration inside a function creates a variable that is not visible *outside* the function. – Pointy Sep 09 '20 at 16:59
  • You define `ifvartruefalse` inside the callback, so the variable is only referencable inside the callback. If you want to make it available outside, define the variable outside, such that it's a lexical ancestor of both the callback and your `if (ifvartruefalse == false){` tests. – CertainPerformance Sep 09 '20 at 17:00
  • Switching the variable to the global scope doesn't solve the problem, see also https://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron – Teemu Sep 09 '20 at 17:05
  • but that tradeoffermanager wont work outside that manager.on, so how could i fix ?? – Robert Kráčalík Sep 09 '20 at 17:08
  • By carefully reading the linked dup and the post I've linked above. – Teemu Sep 09 '20 at 17:11
  • @Teemu could you please show the example ?? cant find my issue... – Robert Kráčalík Sep 09 '20 at 17:48

0 Answers0