Community

Hi everybody! I have an agent class A with an embedded statechart. One transition in this statechart should depend on a variable x (or the result of a method) of another Active Object class B, but this variable has to be static, as it can also be used before any Object of type B is initialised (in fact, the transition should lead to the initialisation of an Object of type B, which is added to the replication variable for B embedded in A). My problem now is, I cannot access such a variable as I would normally do in Java, with B.x. I have declared x public and static, but what I get is an error that says "B.x cannot be resolved or is not a field". If I use a getter-method getX(), it says something different (when I use B.getX() in the code for the transition): "The method getX() is undefined for the type Statechart". Of course I could just declare the variable in Main (and use get_Main().x ), but logically it belongs to B, it's an attribute of all objects of type B, however static. Is there anything special in AnyLogic about accessing static methods and variables (or constants)? Thanks in advance Patrick
Hi Patrick, I am "fighting" with the same problem , have you maybe found any solution?? Best regards, Tomas
Hi, Patrick, Tomas et All. I tried to reproduce the problem without get success. I developed a model following step-by-step the Patrick's description. It can be downloaded from http://zona8.com.br//tech/wp-content/dowloads/anylogic/AcessingStaticVariablesFromAnotherActiveObject.rar and I ask you if it is similar to the yours? May you edit it to reproduce the problem? Kind Regards, Almir Campos. http://tech.zona8.com.br
Hi Almir, My problem is similar to Patrick's and it's described here -> http://www.xjtek.com/support/forum/anylogic6/657/ Best regards Tomas
Thank you for your replys, Almir and Tomas! Your example works for me too, Almir. But the specific problem in my case is, that the static variable in B should contain an instance of CustomDistribution, generated from a table function which of course would also have to be static. Apparently it works with just one static variable (therefore my description was incomplete, sorry for that), but in this case it seems like there is some problem with the order of initialisation. I edited your example, can I send it to you? Kind regards Patrick