This is kind of a dense, code heavy question, I'd appreciate any help... I'm wondering how best to capture when the time changes, in order to do some bookkeeping (like updating my time member variable).
I've made this class:
public class TimeChangedCondition extends Condition { public TimeChangedCondition(Robot bot){ super("TimeChanged", 99); this.bot = bot; this.last_round = -1; this.last_time = -1; } @Override public boolean test() { int round = bot.getRoundNum(); long time = bot.getTime(); boolean time_changed = ((round != last_round) || (time != last_time)); if (time_changed){ last_round = round; last_time = time; } return time_changed; } protected Robot bot; protected int last_round; protected long last_time; }... and put this in my run() method:
this.addCustomEvent(new TimeChangedCondition(this));... and made this event handler:
@Override public void onCustomEvent(CustomEvent e){ if (e.getCondition() instanceof TimeChangedCondition){ time = getTime(); round = this.getRoundNum(); } }... I figure many people probably do something similar, so, is there a better way? And, are there flaws with this method? Is there a gap anywhere, such that in my code, it could be the case that:
((bot.time != bot.getTime()) && (bot.round != getRoundNum()))--BenHorner
public class TimeChangedCondition? extends Condition { MyBotClass? bot;
public TimeChangedCondition?(MyBotClass? bot) { super("TimeChanged?", 99); this.bot = bot; }
@Override public boolean test() { bot.time = bot.getTime(); bot.round = bot.getRoundNum?(); return true; } }