Dear Sebastian.
The SARL grammar definition makes that the guard's code and the event handler's code are in different scopes and cannot share local variables.
Consequently, you cannot use your local variable entity into the guard.
In order to make your code most easy to read, I may propose to you to use the following code:
agent X {
def getEntityState(e : E_EntitySensed) {
MT_getEntityState(e.entityName)
}
on E_EntitySensed [occurrence.entityState.routeLength > 0 && occurrence.entityState.charge > 0] {
val entity = occurrence.entityState
}
}
All the best.
Stéphane.