Jump to content

Whats better?


Recommended Posts

Posted

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.

 

Posted

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

 

 

 

 

  • Like 1
Posted (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 by Nbacon

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...