Skip to main content

EvalOnGo (Java)

Important

This only works if you extend the BlackOp class. More info about that here. It's essentially LinearOpMode with a few extra utilities, and it's made for use with the Blacksmith Library.

If you're using Kotlin, check out createOnGo/evalOnGo for a more versatile and idiomatic method

danger

This is partially in beta, so if you find your code crashing when you add this and it works if you remove it, don't be surprised. It should work though, from my testing.

tip

If you're instantiating a class that doesn't need any args, or only takes a hardwareMap, check out @CreateOnGo instead!

You know how in a typical OpMode you sometimes have to be all like this or something?

private MyArmClass myArm;

@Override
public void init() throws InterruptedException {
myArm = myMethodToCreateAnArm();
}

public MyArmClass myMethodToCreateAnArm() {
return MyArmClass(name, param1, param1, ...);
}

With @EvalOnGo, you can simply do this instead:

@EvalOnGo("myMethodToCreateAnArm")
private MyArmClass myArm; // (Sadly doesn't work with final variables D:)

Yep, that's it. Of course there are some rules though I'll list at the end, read the rest first though.

public class MyOp extends BlackOp {
@EvalOnGo(method="makeMyClaw")
private MyClaw myClaw;

@EvalOnGo(method="makeMyArm1")
private MyArm myArm1;

@EvalOnGo(method="makeMyArm2")
private MyArm myArm2;

private MyClaw makeMyClaw() {
return ...;
}

// It's fine if there's an args version as long as there's a
// no-args overload, such as the above
MyClaw makeMyClaw(int param1) {
return ...;
}

// Will throw an error since there's no no-args version
public MyArm myArm1(String name) {
return ...;
}

// Will throw an error since it returns the wrong type
protected MaiWaife myArm2() {
return ...;
}
}

Calling a static method from another class

danger

Make sure the method you're calling from another class is static and has no args

Just add another parameter called clazz and assign it to whatever class contains the static method.

@EvalOnGo(method="makeArm", clazz=MyArmClass.class)
private MyArmClass myArm;

// ...

class MyArmClass {
public static MyArmClass makeArm() {
// ...
}
}

Rules for @EvalOnGo

  1. @EvalOnGo can work with any public or private function in the class itself (or the class passed in), or it works with any public function in the superclass of the class given.

  2. The given function must have a no-args version or it will error.

  3. The return type of the function must be the same type (or a subtype) as the variable being set by @EvalOnGo

  4. @EvalOnGo won't work with final variables

  5. Make sure the function spelling is correct, like double, quadruple check. All @EvalOnGo errors will only be at runtime.

Provided utility methods

The BlackOp class has, as of now, two utility methods (more will come soon as I think of them)

// 1/2.

@EvalOnGo("getReforgedGamepad1") // Declared in BlackOp, you don't have to declare this method yourself
ReforgedGamepad driver;

@EvalOnGo("getReforgedGamepad2") // Declared in BlackOp, you don't have to declare this method yourself
ReforgedGamepad codriver;

Practical example

Link to Java example

You can check our the Kotlin version as well if you want to see how we really use it, but the syntax is much different for CreateOnGo/EvalOnGo

Link to Kotlin example