NovaLight Posted August 17, 2020 Share Posted August 17, 2020 Hello! I'm looking into creating an FSM frame work for my scripts. I'm curious to see what the best way to do this is. So their are 2 options that I'm looking at: Reflection by invoking methods. Passing the transition method name as a string which is in the main class. Boolean supplier. Passing the transition boolean supplier method which is in the main class. This is just a quick idea I've not full thought about this yet so it might be a little bit more complex. Quote Link to comment Share on other sites More sharing options...
Nbacon Posted August 17, 2020 Share Posted August 17, 2020 Hey I love Finite State Machine. I have made one in my scheme project but for you i would recomend using koltin and do something like this. You need some hacky code for loop backs on it self but I hope you can figure that out. val openbank : () -> () -> Any={ getBank().open() if (getBank().isOpen){ Closebank }else{ quit } } val Closebank: () -> () -> Any ={ getBank().close() if (!getBank().isOpen){ openbank }else{ quit } } var quit ={ stop() } var c= openbank override fun onLoop(): Int { log("test") c= c.invoke() as () -> () -> Any return MethodProvider.random(1000,5000) } or you can program in java with goto like code in a switch stament like @Override public int onLoop() throws InterruptedException { switch (currentFuntion){ case 0: stop(); break; case 1: open(); break; case 2: close(); break; } return 0; } public void open() throws InterruptedException { getBank().open(); if (getBank().isOpen()){ currentFuntion=2; }else { currentFuntion=0; } } public void close(){ getBank().close(); if (!getBank().isOpen()){ currentFuntion=1; }else { currentFuntion=0; } } I have other Ideas but there dumb 1 Quote Link to comment Share on other sites More sharing options...
NovaLight Posted August 19, 2020 Author Share Posted August 19, 2020 Yeah nice! I was thinking more on the lines of a modular FSM keeping almost every action in a separate state classes. Looked at your project, Looks very impressive! Quote Link to comment Share on other sites More sharing options...
Nbacon Posted August 19, 2020 Share Posted August 19, 2020 (edited) 9 hours ago, NovaLight said: ! For some reason Finite and Modular dont realy mix for me. (Kmaps chace super faster when remove and adding terms) Ps (Just a a task system) in class you can do this just follow the koltin example public abstract class Activity{ public abstract void doSomething(); public abstract boolean isDone(); public abstract Activity next() } Edited August 19, 2020 by Nbacon Quote Link to comment Share on other sites More sharing options...