0

I am creating a simple robot in Robocode. I have a function walls shown below:

public void walls() {
        see = false;
        wallBool = true;
        double maxMove = Math.max(getBattleFieldWidth(), getBattleFieldHeight());
        turnLeft(getHeading() % 90);
        ahead(maxMove);

        see = true;
        turnRight(90);
        turnGunRight((getHeading() - getGunHeading())+ 90);

        while (getEnergy() <= 115) {
            wallBool = true;
            see = true;
            ahead(maxMove);
            see = false;
            turnRight(90);
        }
    }

Note that see and wallBool are variables which have already been declared earlier in my code. In the while loop within the function, I call the turnRight(); method, which should automatically scan for other robots. However, my code does not run in my onScannedRobot function, included below:

public void onScannedRobot(ScannedRobotEvent e) {
    System.out.println("check");
    if (see==true) {
        System.out.println("check2");
        scan();
    }

    if (wallBool==true) {
        fire(2);
    }

Check is never printed to the console. What's wrong?

Any help would be greatly appreciated...

Eragon20
  • 483
  • 1
  • 7
  • 20
  • I would recommend simplifying your code to just rotating the radar and printing if you get a scan event. Then building back up to what you have here. – NonlinearFruit Nov 29 '16 at 16:01
  • Also if you are trying to shoot at the scanned robot, using the `ScannedRobotEvent` to place your shot. The sample bots' source code is a great place to start. – NonlinearFruit Nov 29 '16 at 16:03

1 Answers1

-1

Please make sure you have put import robocode.ScannedRobotEvent; in the import. Also keep your public void onScannedRobot(ScannedRobotEvent e) just below public void run() function in case you have changed the order.

pacholik
  • 8,607
  • 9
  • 43
  • 55
asams
  • 19
  • 3