This site requires JavaScript, please enable it in your browser!
Greenfoot back
StrauXX
StrauXX wrote ...

2018/4/30

help with getting a list of neighbour actors with "getOneObjectAtOffset"

StrauXX StrauXX

2018/4/30

#
I wanted to get an ArrayList of the neighbours of an actor at the position x,y, but it doesn't work! this is my code
List neighbours = (getOneObjectAtOffset(x2, y2, blankSquare.class).getNeighbours(1, true, blankSquare.class));
the error is as follows: <A>getNeighbours(int,boolean,java.lang.Class<A>) has protected acess in Greenfoot.Actor
danpost danpost

2018/4/30

#
An actor cannot tell another actor to perform any collision type method as all those type methods have protected access.. That means that in the following line of code:
List neighbours = this.getNeighbours(1, true, blackSquare.class);
you cannot replace 'this' with any other actor. You will have to call a method in the blankSquare class so that the blankSquare object can call the method on itself and return the resulting list.
StrauXX StrauXX

2018/4/30

#
ok, i tried it like this:
List neighbours = getOneObjectAtOffset(x2, y2, blankSquare.class).getNeighbourList();
but it gives me the error "cannot find symbol..."
danpost danpost

2018/4/30

#
You have this:
getOneObjectAtOffset(x2, y2, blankSquare.class).
replacing 'this.', which again you cannot do.
You need to login to post a reply.