S
S
Soft_touch_plastic2020-08-16 12:32:27
JavaScript
Soft_touch_plastic, 2020-08-16 12:32:27

How to change the properties of another class?

Hello, there is a Simulation class, it has a conf property, in which the properties of the current simulation are in the form of a list (number of cells, nanites, etc.). The system assumes active appearance/deletion of Nanit class objects. In the constructor of the Nanit class, I would like to push the ability to change the conf property of the Simulation class, inside which Nanit is created (that is, when creating a new nanite, the constructor of this nanite in the Simulation class object increments the conf.count_nanit property)
In fact, you need to somehow get the object that created the new Nanit and change its property. The object of the Simulation class is guaranteed to be 1
Guessed, inside each Nanit object to store a reference to the simulation, through which it can be changed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-08-16
@Soft_touch_plastic

Of course, you can do it this way - you yourself came up with an option, but it's unnecessary. This will lead to a mess that is difficult to debug. Create, add and remove "nanites" in the "simulation" should only be done using specific methods, in which the entire calculation must be carried out. These properties are "simulation" properties and should only be modified by the simulation itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question