Jump to content

Position problems


Recommended Posts

Posted

Hello everyone, I'm working on a script and I have to go from place A to B because the 2 places are not far from each other and therefore I want to use "walkingEvents".
There is a gate between those two places. My script goes to the place in front of the gate, but I can not get him to open the gate.
Could someone look at my code and tell me what I'm doing wrong?
Still learning the basics so it can be a stupid mistake :)
Thanks in advance.

Spoiler

if (myPlayer().getPosition() == new Position( 3110,9518,0)){
                Entity secondGate = objects.closest(9719);
                secondGate.interact("Open");
            } else if (myPlayer().getPosition() == new Position(3111,9511,0)){
                walkAndTalk();
            } else {
                WalkingEvent event = new WalkingEvent(new Position(3110,9518,0));
                event.setMinDistanceThreshold(0);
                execute(event);
            }

 

 

 

Posted (edited)

If you know where you're going to and where you're coming from, then i'd suggest using paths to walk the distance. Also, rather than using exact positions, you might find areas useful, or even better would be to use reachability checks so that your code is less specific.

Good luck :)

Apa

Edited by Apaec
  • Like 1
Posted (edited)
Quote

myPlayer().getPosition() == new Position( 3110,9518,0)

The "==" operator tests if two references refer to the same object in memory. Since you just created a new Position with the 'new' keyword, they can never be the same object in memory, even if they hold the same coordinates. What you're looking for here is the equals method, which in the Position class is overridden to test coordinate equality.

Though ideally you shouldn't have to rely on specific absolute coordinates.

Edited by FrostBug
  • Like 2

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...