I have a simple function, an event that returns the output, and a private function that runs the code.
I would like to pass the name of the event using the simple function (which calls the private function), so that the private function calls the event. easy enough if it was just strings, but because it is a method it will not work.
@SimpleEvent(description = "Event raised when output returned")
public void GotOutput(final String output) {
EventDispatcher.dispatchEvent(this, "GotOutput", output);
}
@SimpleFunction(description = "set parameters to get output")
public void GetOutput() {
String parameters = "some parameters";
GetFunction(parameters, <GotOutput>);
}
private void GetFunction(String parameters, <event parameter (GotOutput) here>) {
//do something
//output to event:
<event parameter (GotOutput)>(output);
}
In above, the event GotOutput. I want to send GotOutput using the function GetOutput to the function GetFunction, so that it outputs to GotOutput.
It all works if I hard code GotOutput to GetFunction, but i want to be able to apply many simple functions to GetFunction to keep things DRY
In here, the event name is unknown. For example, in App Inventor, you can track the user input, which is strings, and open another screen with that string because App Inventor opening screens accept strings. But in Java, they cannot do something like
Here I have simplified to working code. You can see GotOutput is hard coded in GetFunction and will therefore run the event. But i will have many simpleevents and simplefunctions, so i want to be able to substitute GotOutput for whatever simpleevent is needed for the desired simplefunction. All simplefunctions will call GetFunction.
@SimpleEvent(description = "Event raised when output returned")
public void GotOutput(final String output) {
EventDispatcher.dispatchEvent(this, "GotOutput", output);
}
@SimpleFunction(description = "set parameters to get output")
public void GetOutput() {
String parameters = "some parameters";
GetFunction(parameters);
}
private void GetFunction(String parameters) {
//do something
//output to event:
GotOutput(output);
}