Jump to content

Walking back to previous location


CrashBandiboob

Recommended Posts

Would love some help on how to use positions and walking!
Let me give a bit of background:
Script cuts trees, when inventory is full it walks to chosen bank, deposits all logs, then I would like it to walk back to where it was cutting the trees.

I'll break down what I've got:

I've declared a new variable 'pos' to store the original location of wood cutting and set it as any old value:

public Position pos = new Position(0, 0, 0);



Then when the script sees the inventory is full it sets the value of 'pos' to the closest tree:

RS2Object tree = getObjects().closest(treeName);
....
pos = tree.getPosition();


Script then walks to the chosen bank e.g.:

getWalking().webWalk(Banks.LUMBRIDGE_UPPER);



It does all the banking stuff, closes the bank and then to return to the original position I have tried:

getWalking().walk(pos);



The issue I am having is that pos gets set as the players current location at the bank when trying to return to the closest tree so the player just stays at the bank and goes nowhere. Why does the value of pos get overwritten when? Is there a better way to store the value of pos? Is there a better way to write this code?

 

 

Edited by CrashBandiboob
Link to comment
Share on other sites

11 minutes ago, Medusa said:

Can you send the entire code? It'll make us able to help you better :)

I was worried someone would say that, the code is a mess haha
Here it is:
https://pastebin.com/JAwetg8g

 

1 minute ago, Token said:

Set the value of pos to the current player's position (myPosition()), not the tree position. You cannot walk back to the tree position because that's not walkable, there's a tree blocking that position.

Have tried this, same issue :(

Link to comment
Share on other sites

1 minute ago, CrashBandiboob said:

I was worried someone would say that, the code is a mess haha
Here it is:
https://pastebin.com/JAwetg8g

 

Have tried this, same issue :(

You walk to the bank using webwalking, then use webwalking to get back not normal walking as it's probably no longer in the currently loaded region or cannot be reached without going through obstacles

Link to comment
Share on other sites

7 minutes ago, Token said:

You walk to the bank using webwalking, then use webwalking to get back not normal walking as it's probably no longer in the currently loaded region or cannot be reached without going through obstacles

Good point.
I have changed the setting of pos to:

 pos = myPosition();



And the return walking to:

getWalking().webWalk(pos);



But still does nothing. Tested this by being on the same floor as the bank in Lumby castle and on a different floor

Link to comment
Share on other sites

7 minutes ago, CrashBandiboob said:

Good point.
I have changed the setting of pos to:


 pos = myPosition();



And the return walking to:


getWalking().webWalk(pos);



But still does nothing. Tested this by being on the same floor as the bank in Lumby castle and on a different floor

Then log the pos throughout the script and check where it changes. There is no internal code in our API to change your variables values, it's definitely a logical error in the code.

Link to comment
Share on other sites

There is an overarching problem with the way you are designing the script. It isnt mean to go down through the code and execute everything in order. 

This is how you have it:

    if (condition) do this

    if (condition) do this

If both conditions result to true, then both actions are performed. IT should, instead, only evaluate one condition to true and perform one action per every time the script loops.

This of onLoop as what you want to do in one moment of time based on environmental values at that instance.

you should instead do:

    if (condition) do this

    else if (condition) do this

for example:

    if (bank is not open) open bank

    else if (bank is open) deposit logs

The first iteration of the loop. the bank is not open. So you open the bank. The next iteration, the bank is open. So you deposit the logs.

Inside of each if statement, you can put more if statements to check more conditions, but try to only ever execute one action every time the script loops.

After you get the hang of that, you can look into Events to contain certain actions, and execute 'mini onLoops' throughout the script.

Edit: after looking at it more, I see that you arent completely ignoring else statements, but the banking function shouldn't be doing everything at once

Edited by camaro 09
  • Like 1
Link to comment
Share on other sites

14 hours ago, camaro 09 said:

There is an overarching problem with the way you are designing the script. It isnt mean to go down through the code and execute everything in order. 

This is how you have it:

    if (condition) do this

    if (condition) do this

If both conditions result to true, then both actions are performed. IT should, instead, only evaluate one condition to true and perform one action per every time the script loops.

This of onLoop as what you want to do in one moment of time based on environmental values at that instance.

you should instead do:

    if (condition) do this

    else if (condition) do this

for example:

    if (bank is not open) open bank

    else if (bank is open) deposit logs

The first iteration of the loop. the bank is not open. So you open the bank. The next iteration, the bank is open. So you deposit the logs.

Inside of each if statement, you can put more if statements to check more conditions, but try to only ever execute one action every time the script loops.

After you get the hang of that, you can look into Events to contain certain actions, and execute 'mini onLoops' throughout the script.

Edit: after looking at it more, I see that you arent completely ignoring else statements, but the banking function shouldn't be doing everything at once

Of course! It was so obvious!
Thank you! :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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