I have 2 behaviors being used in a lejos.subsumption example I'm working on:
MainBehavior, and
Interruptor
I also have an ExternalClass - being used by MainBehavior (see below).
The purpose of ExternalClass is to keep a counter, and every time MainBehavior calls one of it's methods the count gets incremented.
I have debugged this and ascertained that it is working.
Example Debug Output:
doing doX()
count is 1
doing doY()
count is 2
doing doY()
count is 3
etc.
My test case is this.
After doing 2 or 3 operations - touch the touch sensor, and Interruptor.action() should print the value of ExternalClass.count to be 2 or 3.
(i.e. If working = count should equal 2 or 3.)
The problem I'm getting is that count is equal to 14 (the size of the list), despite hitting the sensor after 2 or 3 operations (mid for-loop).
I'm wondering if the Arbitrator can't interrupt a for-loop, or somehow the for-loop is completing before Interruptor.action() is called?
---
Code Sample Below
---
class MainBehavior implements Behavior
{
...
ArrayList<String> list = filledList; //has been filled with 14 elements
ExternalClass myClass = new ExternalClass();// has been initialised
...
public void action()
{
for(String s: list) // will loop through 14 String elements of list
{
if(caseX)
{
myClass.doX()
myClass.addToCount();
}
else if (caseY)
{
myClass.doY()
myClass.addToCount();
}
}
}
}
class Interruptor implements Behavior
{
...
public boolean takeControl()
{
return touch.isPressed();
}
public void action()
{
LCD.drawString("sensor fired...",0,3);
Button.waitForPress();
Sound.beep();
LCD.clear();
LCD.drawInt(ExternalClass.getCount(), 0, 3);
}
}
}
class ExternalClass
{
private static int count=0;
public void addToCount()
{
count+=1;
}
public void refresh()
{
count=0;
}
public int getCount()
{
}
}
Anyone any ideas?
