Helping out another modder who is inexperienced, and I almost have the mod working, but I'm not compiling a jar in case that is relevant to this issue. Running into:
Caused by: java.lang.ClassNotFoundException: File 'data/scripts/skills/FieldRepairsNerfScript.java', Line 85, Column 11: Assignment conversion not possible from type "java.lang.Object" to type "com.fs.starfarer.api.fleet.FleetMemberAPI"
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:226)
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:178)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
It seems like I am declaring a type though so where is it getting the idea that I'm trying to convert an object? This is pasted directly from the Field Repairs script, so I have a hunch that its a janino issue or something. Or am I missing something obvious? (Wouldn't be the first time.)
"picked = picker.pick();" is line 85 for refence.
*FIXED* Hmm, ok so apparently the class loader doesn't like it if you declare a type when initializing a new WeightedRandomPicker. So: WeightedRandomPicker<FleetMemberAPI> picker = new WeightedRandomPicker<FleetMemberAPI>();
Should change to: WeightedRandomPicker<FleetMemberAPI> picker = new WeightedRandomPicker<>();Nvm the compiler doesn't like that either. I guess it's not possible to use a WeightedRandomPicker without using a jar?? The reason this is important is because the user wants to play around with one of the static values for testing, and that won't be possible if the script is in a jar. They don't really know how to code and won't want to set up an IDE.
*EDIT* Ah screw it I compiled a jar and made the code read the value from settings so it is easily changed. Simple enough. Works now.
From:
Spoiler
import com.fs.starfarer.api.fleet.FleetMemberAPI;
protected FleetMemberAPI picked = null;
CampaignFleetAPI fleet = Global.getSector().getPlayerFleet();
WeightedRandomPicker<FleetMemberAPI> picker = new WeightedRandomPicker<FleetMemberAPI>();
for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
if (member.getVariant().isStockVariant()) continue;
int dmods = DModManager.getNumNonBuiltInDMods(member.getVariant());
if (dmods > 0) {
picker.add(member, 1);
}
}
picked = picker.pick();