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

2012/8/9

getNeighbours(int) issue? (2nd attempt)

danpost danpost

2012/8/9

#
While testing 'getNeighbours(int)' will return 'anybody's neighbours. That is, if I have a reference to someone's UserInfo called 'ui', I can use 'ui.getNeighbours(15)' to get those users found around whoever is reference by 'ui'. However, on the site, I believe it always returns those around the current user regardless of how I prefix it. Although the correct operation wanted by the team is probably the one we get on the site, I believe that allowing this method to be prefixed by any UserInfo object would be a good idea. It certainly would not take much to allow this, and it would prevent having to read in all users at one time. I am using the USB version for Windows. Any comments and/or responses welcome (please)! Thanks in advance.
davmac davmac

2012/8/10

#
I assume you mean the 'getNearby(int)' method? It is a static method (check the documentation), as such, it doesn't matter what you prefix it with (as long as it's a UserInfo instance, or the UserInfo class name). You should really call it as 'UserInfo.getNearby(...)'.
danpost danpost

2012/8/10

#
Sorry, but yes, I did mean the 'UserInfo getNearby(...)' method. But why is it, that on my laptop, it works like it should (from what you are telling me), and on the Greenfoot site, it does not appear to be doing what it should. Here is what I am doing: first, I use the UserInfo 'getTop(...)' method to get the first 15 UserInfo objects. Then, I use the UserInfo 'getNearby(...)' method using the last UserInfo object returned from the UserInfo 'getTop(...)' call. The same code should work the same on the site as on my laptop, but on the site, I only end up with the first set of UserInfo object returned by the UserInfo 'getTop(...)' call and no more, even though more UserInfo objects are there to retrieve. Any idea why that is?
davmac davmac

2012/8/10

#
For one thing, I think you've misunderstood me. It doesn't matter what object you use to invoke the getNearby() method, it's a static method so the object is ignored - it always returns entries surrounding the current user. You shouldn't really invoke it with an object, you should invoke it as "UserInfo.getNearby(...)"; the fact that you can invoke it with an object is just a peculiarity of Java.
danpost danpost

2012/8/10

#
I was not aware of that particular peculiarity of Java. However, then, it is not working properly in the USB version. Maybe it is an instance method there, instead of being static, because when I prefix it with a UserInfo object, it returns those users around it (not the current user). In other words, this may be a bug in the at-home coding of this method in the USB version for Windows. With this new understanding, I do realize what I need to do (code-wise) to accomplish that which I want to do. I was hoping I would not have to go that route, though. THANKS.
davmac davmac

2012/8/20

#
danpost, I've double-checked and the getNearby(...) method in UserInfo is definitely static, even in the USB version. So it can't possibly make a difference what object you use to invoke it. I hope this makes sense to you. I think you were getting confused because it happens to (in your case) return entries that are roughly surrounding the last entry returned by getTop(...), but that is just coincidence. The methods actually behave as documented.
You need to login to post a reply.