View Single Post
  #20   Spotlight this post!  
Unread 03-05-2014, 14:27
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: Share you Autonomous

Quote:
Originally Posted by notmattlythgoe View Post
Code:
public class DecisionCommand extends Command {

public DecisionCommand (IProvidesDecision decision, Command trueCommand, Command falseCommand) {}

   public void initialize() {
      if (decision.getValue()) {
         trueCommand.initialize();
      } else {
         falseCommand.initialize());
      }
   }

   public void execute() {
      if (decision.getValue()) {
         trueCommand.execute();
      } else {
         falseCommand.execute());
      }

   etc...
}
That looks like it would work. I was pretty sure it would be possible to do something but I thought it might get really ugly really fast. That's a pretty slick way to do it.

Here's something you could do if you wanted to be avoid duplicating the end of command conditions in the subsequent if:
Code:
class Continuable extends Command{
	//I don't remember whether I've set this class up is valid Java...

	//this would return self unless you wnated to run a different command.
	abstract public Continuable next();

	public bool isFinished(){
		return next()==null;
	}
}

class Continues extends Command{
	Continuable current;

	Continues(Continuable cmd){
		current=cmd;
	}

	void initialize(){
		if(current!=null) current.initialize();
	}

	void execute(){
		if(current!=null){
			current.execute();
		}
	}

	bool isFinished(){
		if(current==null) return 1;
		current=current.next();
		return current==null;
	}
}