0

I am in the statechart of the one agent type (Person) and I want to send a message to another agent type (Person2) in a certain state (atHome), but when I use code below the program throws me an error

for( Person2 m : main.person2s ) {

   if( m.inState(atHome)==true ) { 
       send("hi", m);
   }
}

what should I do to call another agent type in a certain state?

  • What's the error? – Emile Zankoul May 30 '22 at 00:09
  • `Exception during discrete event execution: class prueba6.Person2 cannot be cast to class prueba6.Person (prueba6.Person2 and prueba6.Person are in unnamed module of loader 'app') at prueba6.Person$personStatechart_state.getStatechart(Person.java:1) at com.anylogic.engine.IStatechartState.inState(Unknown Source) at com.anylogic.engine.Agent.inState(Unknown Source)` – Sebastian Vásquez May 30 '22 at 02:15

1 Answers1

1

Try this instead

for( Person2 m : main.person2s ) {

   if( m.inState(m.atHome) ) { 
       send("hi", m);
   }
}
Emile Zankoul
  • 2,161
  • 2
  • 6
  • 18