Jump to content

can't get acceptTrade() to work


Recommended Posts

Posted (edited)

I am trying to make my mule accept a trade but for some reason, he wont execute the command, or nothing happens when he executes the command. I can confirm that he is in the first trade window. This command works for my other scripts but for some reason in this script it wont work. I am checking the log and "Accepting Trade" keeps looping so I know that it keeps trying to execute the command. Thanks for the help.UOSRi8I.png

edit: I put this.script.trade.acceptTrade() in an if statement to see if it was returning true but it is returning false. Still not sure why it is returning false though.

edit2: When the bot attempts to accept trade, the mouse hovers over "decline".. 

Edited by Tylersbored
Posted (edited)
14 minutes ago, Tylersbored said:

I am trying to make my mule accept a trade but for some reason, he wont execute the command, or nothing happens when he executes the command. I can confirm that he is in the first trade window. This command works for my other scripts but for some reason in this script it wont work. I am checking the log and "Accepting Trade" keeps looping so I know that it keeps trying to execute the command. Thanks for the help.UOSRi8I.png

edit: I put this.script.trade.acceptTrade() in an if statement to see if it was returning true but it is returning false. Still not sure why it is returning false though.

Why are you using while loops? Firstly the script is already looping, (the method is even called onLoop) and you also only want to be offering items and accepting trade once.

Your code should be structured more like:

If not in trade with player then trade player

Else if first window and not offered coins then offer coins

Else if not accepted trade window accept trade window

Edited by Explv
Posted
4 minutes ago, Explv said:

Why are you using while loops? Firstly the script is already looping, (the method is even called onLoop) and you also only want to be offering items and accepting trade once.

Your code should be structured more like:

If not in trade with player then trade player

Else if not accepted trade window accept trade window

can u write me the code plz

Posted
15 minutes ago, Explv said:

Why are you using while loops? Firstly the script is already looping, (the method is even called onLoop) and you also only want to be offering items and accepting trade once.

Your code should be structured more like:

If not in trade with player then trade player

Else if first window and not offered coins then offer coins

Else if not accepted trade window accept trade window

Ah I see. I just started writing scripts about a week ago so sorry for the spaghetti code haha. Anyways, I restructured my code to your advice and it seems to be working now, thanks!aJnXchX.png

Posted
5 minutes ago, Tylersbored said:

Ah I see. I just started writing scripts about a week ago so sorry for the spaghetti code haha. Anyways, I restructured my code to your advice and it seems to be working now, thanks!aJnXchX.png

Also, those static sleeps on every second line are pretty obsolete. You could throw in more cond sleeps, though.

Posted (edited)
50 minutes ago, Tylersbored said:

Ah I see. I just started writing scripts about a week ago so sorry for the spaghetti code haha. Anyways, I restructured my code to your advice and it seems to be working now, thanks!aJnXchX.png

In my opinion, it should be more like:

if not is currently trading:
    if interact "Trade with" on worker is successful:
        Conditional sleep until is currently trading
else if not my offer contains coins:
    if enter amount dialog is visible:
        type 35k
    else if interact "Offer-x" on "Coins" is successful:
        Conditional sleep until enter amount dialog is visible
else if not accepted trade:
    accept trade

Interactions can fail, so you shouldn't continue with other interactions unless you know the first one succeeded. For example, in your code you type 35k after interacting with the Coins, but the Coin interaction might fail (it probably won't), and your bot will just type 35k into the chatbox.

Edited by Explv
Posted
1 hour ago, Explv said:

In my opinion, it should be more like:


if not is currently trading:
    if interact "Trade with" on worker is successful:
        Conditional sleep until is currently trading
else if not my offer contains coins:
    if enter amount dialog is visible:
        type 35k
    else if interact "Offer-x" on "Coins" is successful:
        Conditional sleep until enter amount dialog is visible
else if not accepted trade:
    accept trade

Interactions can fail, so you shouldn't continue with other interactions unless you know the first one succeeded. For example, in your code you type 35k after interacting with the Coins, but the Coin interaction might fail (it probably won't), and your bot will just type 35k into the chatbox.

Oh wow. That structure looks alot better.. Thank you so much man, I'll try to follow this principle from now on. Time to go change all my code rip.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...