Trying to work out how to define vars for a parent model so that any other model I create with
model m = createModel(model1);
syntax will have its own copy of those vars. All I can find is:
"SpawnerIsParent
Sets CurrentModel as 'Parent' to the spawned model. If a model has a parent then it will automatically be removed when its parent is removed."
As always, help is much appreciated,
Mic.
Model inherits vars from parent
Moderator: Moderators
The use of the word "parent" in your question is a bit confusing, as that doesn't have anything to do with clones / instances.
Anyway, when you create a clone using the SpawnModel component or CreateModel¹ function, the created clone has a unique copy of all components that the original Model contains² If you want to add variables to a Model, the proper location to do that is in the Definitions node.
¹ Should have been called SpawnClone instead, since that's what it does
² Because of this, only put a component in a Model when it has to be unique to each clone.
K
re parent etc
yeh this came at the end of a lot of coding attempts ...... from the beginning ... Ballz example:
- duplicate BallModel to BallModel1
- rename BallModel1 vars back to iX and iY
- cannot do it - duplicate vars message
iX and iY are instance vars for class BallModel, but any Mode class should be able to have them also ..... it seems they are behaving as global vars .... inconvenient as I want any model to be able to have its own iX and iY, so a central function can address CurrentModel.iX and CurrentModel.iY. TIA,
Mic
- duplicate BallModel to BallModel1
- rename BallModel1 vars back to iX and iY
- cannot do it - duplicate vars message
iX and iY are instance vars for class BallModel, but any Mode class should be able to have them also ..... it seems they are behaving as global vars .... inconvenient as I want any model to be able to have its own iX and iY, so a central function can address CurrentModel.iX and CurrentModel.iY. TIA,
Mic
Hi Mic,
Still not exactly sure what you're trying to do, but indeed .. all component names are global and therefore have to be unique, even when they are placed in the Definitions node of a Model.
Anyway, you probably want to use ModelStates. That way you can have both a Apple and a Banana use the same Price variable.
K
Still not exactly sure what you're trying to do, but indeed .. all component names are global and therefore have to be unique, even when they are placed in the Definitions node of a Model.
Anyway, you probably want to use ModelStates. That way you can have both a Apple and a Banana use the same Price variable.
K
- Attachments
-
- ModelState.png (16.87 KiB) Viewed 19733 times
re: ModelStates
Thank you very much for this - sheds a lot of light on the matter!
Once I have
model m = createModel(Wrapper);
can I somehow do a
m.modelState = Ball1; ?
Thanks
Once I have
model m = createModel(Wrapper);
can I somehow do a
m.modelState = Ball1; ?
Thanks