Loading...
 

PogamutUT2004


players.getNearestVisiblePlayer() throws null

Hi

My question is: Why "players.getNearestVisiblePlayer()" throws null in HunterBot.java, but for example in RaytracingBot.java throws existing bot, not null? This also applies to all get_xxx_Plater() functions....

or why "players.getPlayers();" throws map in RaytracingBot.java, but in HunterBot.java throws null??

thanks, Lukas
Hi!

Thanks for reporting going to check it out...

This is the code

public Player getNearestVisiblePlayer() {
return DistanceUtils.getNearest(players.visible.values(), lastSelf.getLocation());
}


It can (should) only throw NPE iff lastSelf is null - which is in the case you call it before first logic() is invoked.

Can you provide full stacktrace for the NPE?

Best,
Jakub
Hi

this is output of console : extract http://leteckaposta.cz/135085497

I only added System.out.println(" --- > out: " + players.getNearestVisiblePlayer().getName()); to logic() ...

thx. Lukas
Which version of Pogamut are you running?

HunterBoj.java:291 is currently

}


What is your code at line "291" in the HunterBot example?

Nevertheless your code is likely to throw NPE anyway because "players.getNearestVisiblePlayer()" evaluates to NULL in case you do not see any player. Thus calling "getName()" on it will result in NPE.

Best,
Jakub
I already changed the code, but now it's just throws one error, sometimes

Cause: class java.lang.NullPointerException: null (at cz.cuni.amis.pogamut.ut2004.examples.hunterbot.HunterBot.logic(HunterBot.java:281))

code at line 281:

System.out.println("nearestItem(" + info.getNearestItem().getType().getName() + "," + info.getNearestItem().getNavPointId().getStringId()+ ").");

i think probably sometimes info.getNearestItem() throws null, i solve it with condotion

I have one more question:
I want to find out more about all bots (players), but only what I have is locations & weapon

.............
System.out.println("onPostition(" + tmap.get(k).getName() + "," + tmap.get(k).getLocation() + ").");
System.out.println("equippedWeapon(" + tmap.get(k).getName() + "," + tmap.get(k).getWeapon() + ").");
.............

I want to get healt, or for example bot1 is shoting on bot2 etc., or isMoving(bot1,dm_flux2_pathNode_5).?? and more...

thx
Correct, any "getNearest" method may return null, always check.

Regarding "one bot is shooting another", that's probably impossible to sense correctly from UT2004Bot (it is possible when you utilize UT2004Observer for observation of all bots).

At least, you may say whether some other bot is shooting or not by obtaining the Player instance (e.g. from players.getVisiblePlayers())
and then check whether Player.isShooting() is true.

Jimmy
 

News

News RSS RSS feed for News link



Pogamut

Quarterly RSS RSS feed for quarterly reports

Acknowledgement

This work is supported by GA UK 1053/2007/A-INF/MFF (2007-8), GA UK 351/2006/A-INF/MFF (2006-8), the Ministry of Education of the Czech Republic (grant MSM0021620838) (2008-9), by the Program "Information Society" under project 1ET100300517 (2006-9), and the project Integration of IT Tools into Education of Humanities (2006-8) and by the project CZ.2.17/3.1.00/31162, which are financed by the European Social Fund, the state budget of the Czech Republic, and by the budget of Municipal House Prague.