Jump to content

Path works in reverese


jamesst78

Recommended Posts

When I create a list of Positions as a path , and walk it , it walks the reversed path , any idea why is that?

 

pathToAltar.add(new Position(3013, 3356, 0));
    		pathToAltar.add(new Position(3010, 3360, 0));
    		pathToAltar.add(new Position(3006, 3360, 0));
    		pathToAltar.add(new Position(3005, 3356, 0));
    		pathToAltar.add(new Position(3006, 3348, 0));
    		pathToAltar.add(new Position(3006, 3339, 0));
    		pathToAltar.add(new Position(3005, 3326, 0));
    		pathToAltar.add(new Position(3006, 3314, 0));
    		pathToAltar.add(new Position(3006, 3308, 0));
    		pathToAltar.add(new Position(3004, 3302, 0));
    		pathToAltar.add(new Position(3002, 3298, 0));
    		pathToAltar.add(new Position(2995, 3295, 0));
    		pathToAltar.add(new Position(2989, 3292, 0));

walking.walkPath(pathToAltar);

 

Link to comment
Share on other sites

When you added your positions, you may have added them in a reversed order. Try recreating the array/list with the current positions reversed. Or you could do it through code at runtime with a quick Java call.

Collections.reverse(pathToAltar);

Edit:

Just tested the current list you have and it seems to walk correctly from the bank to the air altar, if that is what you are intending. If so than you may have an issue with another part of your script somewhere. Is their more to this script or is it just executing the walking from above?

Edited by BravoTaco
Link to comment
Share on other sites

2 hours ago, BravoTaco said:

When you added your positions, you may have added them in a reversed order. Try recreating the array/list with the current positions reversed. Or you could do it through code at runtime with a quick Java call.


Collections.reverse(pathToAltar);

Edit:

Just tested the current list you have and it seems to walk correctly from the bank to the air altar, if that is what you are intending. If so than you may have an issue with another part of your script somewhere. Is their more to this script or is it just executing the walking from above?

Yes this is exactly what I intend , maybe I have an issue in my script in some other part ,I have a helper method that configures the script to a certain mode , for example "Air" and accordingly it replaces the "pathToAltar" with a new path , I'll try to check my code once more maybe the issue is there , thanks alot , I'm glad to hear its working so the issue is within my code

Link to comment
Share on other sites

2 hours ago, BravoTaco said:

When you added your positions, you may have added them in a reversed order. Try recreating the array/list with the current positions reversed. Or you could do it through code at runtime with a quick Java call.


Collections.reverse(pathToAltar);

Edit:

Just tested the current list you have and it seems to walk correctly from the bank to the air altar, if that is what you are intending. If so than you may have an issue with another part of your script somewhere. Is their more to this script or is it just executing the walking from above?

I found a very weird issue in my code , when I have a list called "pathToBank" and I let it = pathToAltar , then I do Collections.reverse(pathToBank) it changes both pathToAltar and pathToBank to the reversed version of pathToAltar , does this have to do with Java refrencing? did I mess something up? to my knowledge , it shouldn't affect pathToAltar at all
 

 	switch(modeName[index]) {
    	case("Air"):{
    		bankArea = new Area(3008, 3359, 3022, 3352);
    		altarArea = new Area(2980, 3295, 2991, 3283);
    		
    		//rcArea = 
    		pathToAltar = new ArrayList<Position>();

    		pathToAltar.add(new Position(3013, 3356, 0));
    		pathToAltar.add(new Position(3010, 3360, 0));
    		pathToAltar.add(new Position(3006, 3360, 0));
    		pathToAltar.add(new Position(3005, 3356, 0));
    		pathToAltar.add(new Position(3006, 3348, 0));
    		pathToAltar.add(new Position(3006, 3339, 0));
    		pathToAltar.add(new Position(3005, 3326, 0));
    		pathToAltar.add(new Position(3006, 3314, 0));
    		pathToAltar.add(new Position(3006, 3308, 0));
    		pathToAltar.add(new Position(3004, 3302, 0));
    		pathToAltar.add(new Position(3002, 3298, 0));
    		pathToAltar.add(new Position(2995, 3295, 0));
    		pathToAltar.add(new Position(2989, 3292, 0));
    			  
    		pathToBank = pathToAltar;
    		Collections.reverse(pathToBank);   //this messes up both variables not only pathToBank
    		
    		break;
    	}
    	}


 

Quote

 

 

1 minute ago, jamesst78 said:

I found a very weird issue in my code , when I have a list called "pathToBank" and I let it = pathToAltar , then I do Collections.reverse(pathToBank) it changes both pathToAltar and pathToBank to the reversed version of pathToAltar , does this have to do with Java refrencing? did I mess something up? to my knowledge , it shouldn't affect pathToAltar at all
 


 	switch(modeName[index]) {
    	case("Air"):{
    		bankArea = new Area(3008, 3359, 3022, 3352);
    		altarArea = new Area(2980, 3295, 2991, 3283);
    		
    		//rcArea = 
    		pathToAltar = new ArrayList<Position>();

    		pathToAltar.add(new Position(3013, 3356, 0));
    		pathToAltar.add(new Position(3010, 3360, 0));
    		pathToAltar.add(new Position(3006, 3360, 0));
    		pathToAltar.add(new Position(3005, 3356, 0));
    		pathToAltar.add(new Position(3006, 3348, 0));
    		pathToAltar.add(new Position(3006, 3339, 0));
    		pathToAltar.add(new Position(3005, 3326, 0));
    		pathToAltar.add(new Position(3006, 3314, 0));
    		pathToAltar.add(new Position(3006, 3308, 0));
    		pathToAltar.add(new Position(3004, 3302, 0));
    		pathToAltar.add(new Position(3002, 3298, 0));
    		pathToAltar.add(new Position(2995, 3295, 0));
    		pathToAltar.add(new Position(2989, 3292, 0));
    			  
    		pathToBank = pathToAltar;
    		Collections.reverse(pathToBank);   //this messes up both variables not only pathToBank
    		
    		break;
    	}
    	}


 

 

I think what I'm lacking is maybe initialize pathToBank as a new ArrayList<Position> instead of making it just a reference pointer?

Link to comment
Share on other sites

Yeah you are correct, you are essentially setting the pathToBank as a pointer to the pathToAltar so when accessing the pathToBank variable you are actually just accessing the value stored in the pathToAltar. Subsequently if you were to change the pathToAltar value than you would also essentially be changing the value of pathToBank since it is a pointer to that value.

  • Like 1
Link to comment
Share on other sites

11 hours ago, BravoTaco said:

Yeah you are correct, you are essentially setting the pathToBank as a pointer to the pathToAltar so when accessing the pathToBank variable you are actually just accessing the value stored in the pathToAltar. Subsequently if you were to change the pathToAltar value than you would also essentially be changing the value of pathToBank since it is a pointer to that value.

Thanks alot! I fixed it by deep cloning instead of shallow cloning

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