Heres my whole ScannedRobotEvent, with the broken parts commented:
publicvoidonScannedRobot(ScannedRobotEvente){//radarlockingcodedoublelife=getBearingRadians();System.out.println("hislifeis"+life);inti=0;doubleturnBack=getHeadingRadians()+e.getBearingRadians()-getRadarHeadingRadians();setTurnRadarRightRadians(Utils.normalRelativeAngle(turnBack));booleanleft,right;//makesureheisalwaysmoving90degreesfromtheenemy,andonlyshootsifthegunispointingcloseenoughtotheradar//troublewiththis,willoftengointoendlessspinorjamaaginstwallsD://theifvelocityisnt0shouldfixallofthis,hopefully//if(i>0){//if(ScannedRobotEvent.getBearing()>=oldPlace){//right=true;//}//if(ScannedRobotEvent.getBearing()<=oldPlace){//left=true;//}//}//doubleoldPlace=ScannedRobotEvent.getBearing();i++;if(getX()>600||getX()<200||getY()>600||getY()<200){dir=-dir;}if(getVelocity()==0){setAhead(Double.POSITIVE_INFINITY*dir);System.out.println("startingtomoveagain");}if(getRadarHeadingDegrees()>getGunHeadingDegrees()-3&&getRadarHeadingDegrees()<getGunHeadingDegrees()+3){//prerequisitforshooting,assumingradarislockedonenemy//if(ScannedRobotEvent.getDistance()>500){//pow=1;//}//if(ScannedRobotEvent.getDistance()<500){//pow=2;//}//if(ScannedRobotEvent.getDistance()<200){//pow=3;//}//setFire(pow);//System.out.println("firing. power level: "+pow);}if(getRadarHeadingRadians()>getGunHeadingRadians()){setTurnGunRight(5);System.out.println("turninggunright");}if(getRadarHeadingRadians()<getGunHeadingRadians()){setTurnGunLeft(5);System.out.println("turninggunleft");}if(getRadarHeadingDegrees()>getHeadingDegrees()+90){setTurnRight(10*dir);System.out.println("turningright");}if(getRadarHeadingDegrees()<getHeadingDegrees()+90){setTurnLeft(10*dir);System.out.println("turningleft");}System.out.println("ran all scanned ifs");}
Anyone else had this problem? Any info will be appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is a bit unclear to me, what the problem is. That is, what you cannot do,
which you want to do?
For example, in your code you write:
// radar locking code
double life = getBearingRadians();
System.out.println("his life is " + life);
But getBearingRadians() returns the bearing for your robot, not the scanned
enemy. In addition, you get the life with the getEnergy() method, not
getBearingRadians(). So if you want to write out the energy of the scanned
enemy (his life), you should write "double life = e.getEnergy();" instead.
Hence, I am a bit confused.
Try to explain it with a smaller code example so it does not get too
complicated. :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
AFAIK, there are no getBearing() or getBearingRadians() methods in the Robot
class (or any of it's subclasses). It makes sense when you think about it. Why
would you want to get bearing to yourself? :)
Also, in Java, you must initialize all local variables. Otherwise it won't
compile. For example
void someMethod() {
boolean left;
if (/*some condition*/) {
left = true;
}
}
The Java compiler won't let you get away with something like that, and that's
exactly what you're doing in your code.
As for getVelocity() method -- it can be called anywhere within a class that
extends Robot, of course. I do it all the time. :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello internet
in my
event, I can't call certain values like
and
.
However, different
values can be retrieved, like
.
Heres my whole ScannedRobotEvent, with the broken parts commented:
Anyone else had this problem? Any info will be appreciated.
oh god this is hideous how do I clean it up? I don't see an edit button
It is a bit unclear to me, what the problem is. That is, what you cannot do,
which you want to do?
For example, in your code you write:
But getBearingRadians() returns the bearing for your robot, not the scanned
enemy. In addition, you get the life with the getEnergy() method, not
getBearingRadians(). So if you want to write out the energy of the scanned
enemy (his life), you should write "double life = e.getEnergy();" instead.
Hence, I am a bit confused.
Try to explain it with a smaller code example so it does not get too
complicated. :-)
public void onScannedRobot(ScannedRobotEvent e)
event, I can't call certain values like
getBearing()
AFAIK, there are no getBearing() or getBearingRadians() methods in the Robot
class (or any of it's subclasses). It makes sense when you think about it. Why
would you want to get bearing to yourself? :)
Also, in Java, you must initialize all local variables. Otherwise it won't
compile. For example
The Java compiler won't let you get away with something like that, and that's
exactly what you're doing in your code.
As for getVelocity() method -- it can be called anywhere within a class that
extends Robot, of course. I do it all the time. :)