Jump to content

Whats better?


NovaLight

Recommended Posts

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.

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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