Closed chapuisk closed 1 year ago
Actually, the way you are calling the action in on_change:
is accepted, but it should warn you or even make an error at compile time -- and it doesn't, that's where the issue lies -- about the fact that you mix up the action you are running between the simulation(s) and the experiment.
When defined on an attribute of an agent (simulation, experiment, regular agent), the action should be declared in this agent. This is why, if you declare on_change:
on a parameter in an experiment, it will fail to run the action in the simulation (it's logic : in case of multiple simulations, which one should be picked ?). This is the cause of the error you are having. In any case, this way of calling actions should not be demonstrated/used too much, as it has a number of flaws.
Better use the block syntax, e.g. on_change: {ask simulations {do donothing();}}
or directly the block at the end, if you want to run it on the simulations managed by this experiment. Or use simulation
to get the one managed by the parameters panel. Or put the action in experiment
and simply write on_change: {do donothing();}
.
You have an example in Building Elevation.gaml
on how it can be used to do pretty cool things.
After that, I did not look at the second model as it seems a different issue, but keep in mind that playing with on_change:
too much while a simulation is running will inevitably raise errors due to the concurrency between the different operations. It should be used with parsimony, for instance to make sure that parameters remain coherent with one another, etc.
Describe the bug
I am afraid there is no simple way to "clearly and concisely" describe the bug. I'de try to reproduce this issue in a simple model but failed. In few worlds: I attached behavior of the model to a slider parameter, with on_change facet pointing toward an action of the world that changes agent attributes. It lead to an error that stops the simulation.
To Reproduce
evaporation_per_cycle
parameter (works exactly the same withdiffusion_rate
)action donothing {}
on_change: donothing
Expected behavior Makes it work properly or prevent the use of on_change over float parameters.
Desktop (please complete the following information):
Additional context
The error message is a bit different in my case: working on one of my model with agent having a string variable to "A" or "B" that drives they behavior. I use the on_change facet to dynamically update the proportion of agent being in state A or B: a float parameter from 0 to 1 is read by global that update the proportion of agent being A or B. When I play with it while the simulation of the model is running, I got an error nil value detected. Here is my model: