Create own triggers

Hi,

i thought about a solution to handle Mouse-Events which happens concurrent. I dont want to use the solution to set booleans for hitting a button or else…It should be only one Trigger which is executed when i.e. the left Button is pressed and the Mouse moves to left x-axis. And not using both triggers for MouseButton and MouseAxis…



My code-Example:



[java] public class MouseTrigger implements Trigger {



private int mouseAxis;

private boolean negative;

private int mouseButton = 4;



public MouseTrigger(int mouseAxis, boolean negative, int mouseButton) {



if (mouseAxis < 0 || mouseAxis > 2)

throw new IllegalArgumentException("Mouse Axis must be between 0 and 2");



this.mouseAxis = mouseAxis;

this.negative = negative;



if (mouseButton < 0)

throw new IllegalArgumentException("Mouse Button cannot be negative");



this.mouseButton = mouseButton;



}



public String getName() {

String sign = negative ? ("Negative Mouse Button" + mouseButton) : ("Positive Mouse Button " + mouseButton);



switch (mouseAxis){

case MouseInput.AXIS_X: return "Mouse X Axis " + sign ;

case MouseInput.AXIS_Y: return "Mouse Y Axis " + sign;

case MouseInput.AXIS_WHEEL: return "Mouse Wheel " + sign;

default: throw new AssertionError();

}

}



public static int mouseHash(int mouseAxis, boolean negative, int mouseButton){



assert (mouseAxis >= 0 && mouseAxis <= 255) && (mouseButton >= 0 && mouseButton <= 255);

return (((negative ? 768 : 512) | (mouseAxis & 0xff)) & (256 | (mouseButton & 0xff)));



}



public int triggerHashCode() {

return mouseHash(mouseAxis, negative, mouseButton);

}





}

[/java]



It is a combination of the MouseAxis-Trigger and the Mouse-Buttontrigger. But it does not work how i want it to.

I think it is problem in the HashCode…

My Question is: Is it generally not possible to push a new Trigger in J-Monkey-Engine? Or what is my fault in this case? I know it works with a set of boolean variables but i want to make it in another way…

haven’t tried making my own trigger, but you can use combo moves for this:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:combo_moves

1 Like

What you want is a simple finite state machine.

Is there any “finite state machine” yet? :slight_smile: I dont know how to code this…

Hehe I remembered last 2 semesters of course with @normen 's phrase, where we developed a compiler, as part of the computer science course.



And I failed to discover if you can do that without changing lots of things (just like you tried).

I think the opinion to create my own trigger is easier to handle :slight_smile: But for that i have to understand, how the trigger treats an event. Is the hashcode of the trigger the important thing, with what JME react?

You cannot create a new Trigger implementation because those types are handled directly by InputManager. You will need to modify InputManager to do this.



The closest you can come to doing what you asked is by emulating a Joystick and having one of the buttons be triggered by your own code, you can do this by implementing the JoyInput interface. But IMO that’s a really backwards way of doing it really…

1 Like

Thanks. I will prefer the easiest way: setting booleans for button-clicks… Thanks for answers!