Page 1 of 1

Model inherits vars from parent

Posted: Fri Nov 11, 2011 6:50 am
by Mic
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.

Posted: Fri Nov 11, 2011 1:03 pm
by Kjell
:?:

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

Posted: Sat Nov 12, 2011 3:17 am
by Mic
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

Posted: Sat Nov 12, 2011 12:02 pm
by Kjell
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

re: ModelStates

Posted: Sat Nov 12, 2011 8:20 pm
by Mic
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

Posted: Sun Nov 13, 2011 6:34 pm
by Kjell
Hi Mic,
Mic wrote:can I somehow do a m.modelState = Ball1; ?
Unfortunately not .. there's no script / expression equivalent to the SetModelState component.

K