I am writing this before I have tried your suggestion as I won't be at my computer for awhile and wanted to explain what I am trying to do in case I am going down the wrong path
Zitat:
None of this is valid Java code. It looks like you might be trying to use Javascript. This will not work. Java and Javascript have similarities, but are two completely different things.
Haha, I've never used java or javascript before a few weeks ago when I decided to try and use extended commands and everything I have learned is from you and google
Not sure I can tell the difference in them. I have self taught myself pieces of many different languages over the years. I know a little about lots of different languages, but I am a Master of none of them
I have been able to write 1700 lines of java so far in this project.
Zitat:
It's hard to give you any advice, because I don't know what you are actually trying to achieve. You can't pass methods as parameters in Java. The closest thing is using functional interfaces. Something along these lines:
Basically I have multiple methods I want to call that are stored in a List. I am doing this as I want them to run in a certain order. I can write the code to check for the name of the method and then call it, but I would need to add one for every method. I just thought if I could call the method name with a variable I would only need to write the code once for any number of methods.
For instance: (Code not tested, just quickly wrote)
Code:
List myList = new ArrayList();
myList.add(new String[] { "test", "something", "more something" });
myList.add(new String[] { "learn", "something", "more something" });
for (i=0; i<myList.size(); i++) {
String cmd = myList.get(i)[0]; //this would be the method that I want to run
String arg1 = my list.get(i)[1]; //this would be an argument
String arg2 = my list.get(i)[2]; //this would be an argument
cmd(arg1, arg2); // This is what I want to run
}
Some methods have more args. I could make all methods the same number of arguments easily.
String cmd could be any number of different methods
It looks like I will need to put all the methods in a class and use an interface or something of the sort.
Hopefully that makes sense
I am still calling them methods only until I figure the correct way to do it
Zitat:
Building.getCost() ist not used any more. A long time ago, the server provided a cost for every building, but nowadays it's done via building types, so you have to access
getBuildingType().getMaintenanceItems() or possibly getMaintenance(EresseaConstants.I_USILVER).
I just played with this a little and I can get it to return "silver", but haven't been able to find the silver amount yet. I'll keep playing with it when I have time.
UPDATE: I got this working after a little trial and error.
While looping through all the buildings in the region I run:
Code:
int VARmaintAmount = 0;
if (helper.getBuilding(VARbldgID).getOwnerUnit().getFaction().getID().equals(world.getOwnerFaction())) {
for (Item item : DICTbuildings.get(i).getBuildingType().getMaintenanceItems()) {
if (item.getName().equals("silver")) {
VARmaintAmount = item.getAmount();
}
}
}
Not sure if it can be done an easier way, but this returns the silver maint on a building.