Jump to content

State-Node Framework


Joseph

Recommended Posts

The node interface is Activity 

public interface Activity	{
	public String status();
	public boolean validate() throws InterruptedException;			
	public void run() throws InterruptedException;
}

The is the Task manager

public class TaskTracker	{
	private Activity activeTask;
	private Activity[] taskList;

	public TaskTracker(Activity[] taskList)	{
		this.taskList = taskList;
	}
	
	public Activity getActive() throws InterruptedException	{
		if (this.activeTask == null || !this.activeTask.validate())	{
			for (Activity task: taskList)	{
				if (task != null && task.validate())	{
					this.activeTask = task;
					break;
				}
			}
		}		
		return this.activeTask;
	}
}

  • Like 1
Link to comment
Share on other sites

How is this different from what the getState framework does

great of you to ask.

It has the same characteristics. the difference between mine and the getState is that. In getState you are always looping through all the task and grabbing the valid node. But with my Class you will loop through all nodes, grab the valid one. the class will set the valid node as a state in the class. The class will always ref back to the state. If the node is invalid the class will look for a new node. if the node is still active and valid the class will stay with that one node until it is invalid or null.

I wanted to add in a void set node but I forgot to do that On top of that I already left my house so I'll change it later.

Edit: you won't fully understand it until you actually implement it. for fun implement this frame work to an existing class that supports getState and you will understand what I mean.

A priority system would be a good addition to this, other than that, nice snippet.

that's on my to do list Edited by josedpay
Link to comment
Share on other sites

Would you mind sharing a small implementation of this?

For example; what kind of class would/could implement the Activity interface?

It's like a regular node. Create a class, implement activity. Then override the methods. if you have an instance of script within the class then your good to go.

Example:

Private class Mine implements activity {

Override status for name of task

Override the boolean. If inventory is not full, mine

Override the run method mining event (mentioned to be executed) make sure you have an active script instance

}

Ill release and example in a few mins

Edited by josedpay
Link to comment
Share on other sites

It's like a regular node. Create a class, implement activity. Then override the methods. if you have an instance of script within the class then your good to go.

Example:

Private class Mine implements activity {

Override status for name of task

Override the boolean. If inventory is not full, mine

Override the run method mining event (mentioned to be executed) make sure you have an active script instance

}

ill try using this when i get home
Link to comment
Share on other sites

Ok so the class implementing Activity isn't supposed to perform any looping right?

nope. The only looping that actually happens in within the tracker class. Also it only happens once when the method getActivity() i call because of this if statement 

if (this.activeTask == null || !this.activeTask.validate())	{

if that method returns true for any reason it will loop through the array of nodes and grab the new node

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...