There is a rectangle inside a RailCar object representing a wagon which I need to change its color inside the Train object dynamically. The train includes a few railcars. I tried this code:
this.getCar(0).rectangle.setFillColor(maroon)
but I get an error which I am not sure how to address: "rectangle cannot be resolved or is not a field". Any idea would be appreciated.
getCar(int i) returns an object of type 'agent'. To access elements inside of the RailCar agent you need to cast the returned value to a RailCar. The following code should work for this.
((RailCar)this.getCar(0)).rectangle.setFillColor(maroon)
I'm assuming here that you're calling this line of code from within your train agent.