12.02.2017 11:18
15.02.2017 10:49
15.02.2017 16:46
16.09.2020 13:27
22.09.2020 10:26
22.09.2020 14:57
07.10.2020 05:05
12.10.2020 23:06
14.10.2020 00:33
15.10.2020 13:56
You mean the total earnings of a faction? There is no simple way to get this.
world.getDate().getDate()
CoordinateID test1 = region.getCoordinate();
Region test2 = world.getRegion(test1);
addMessage(unit, test2);
16.10.2020 21:51
18.10.2020 15:08
import magellan.library.*;
import magellan.library.rules.*;
test(Unit unit, int a) {
helper.addOrder(unit, "Success " + a);
}
String str = "test";
int a = 1;
window[str](unit, a);
eval("var cmd = " + str); cmd(unit, a);
20.10.2020 15:05
bonzai911 hat geschrieben:I am trying to call a method that is a variable. [...]
- Code:
String str = "test";
int a = 1;
window[str](unit, a);
eval("var cmd = " + str); cmd(unit, a);
interface Doer {
public void do(Unit u, int a);
}
...
class MyAdder implements Doer {
public void do(Unit u, int a) {
{
helper.addOrder(unit, "Success " + a);
}
}
...
public void doThingsWithDoer(Doer doer) {
...
Unit unit = ...
doer.do(unit, 5);
}
...
public void variableCallerOfDoThings() {
...
doThingsWithDoer(new MyAdder());
}
20.10.2020 21:54
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.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.
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.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:
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
}
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.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).
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();
}
}
}
21.10.2020 13:19
bonzai911 hat geschrieben:Not sure if it can be done an easier way, but this returns the silver maint on a building.
interface Interpreter {
public void accept(String [] parameters);
}
class TestInterpreter implements Interpreter {
public void accept(String[] parameters) {
// do stuff
}
}
...
Map<String, Interpreter> interpreters = new HashMap<String, Interpreter>();
interpreters.put("test", new TestInterpreter());
interpreters.put("improvise", new Interpreter() {
public void accept(String [] parameters) {
// do other stuff
}
}
interpreters.put("lambdaexpression", (parameters) -> {
// do cool stuff
}
);
...
interpreters.get("test").accept(new String[] {"something", "other"});