Model inherits vars from parent

Discuss the ZGameEditor Visualizer plugin for FL-Studio.

Moderator: Moderators

Post Reply
Mic
Posts: 47
Joined: Mon May 30, 2011 8:10 pm

Model inherits vars from parent

Post 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.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Mic
Posts: 47
Joined: Mon May 30, 2011 8:10 pm

re parent etc

Post 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
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
ModelState.png
ModelState.png (16.87 KiB) Viewed 17339 times
Mic
Posts: 47
Joined: Mon May 30, 2011 8:10 pm

re: ModelStates

Post 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
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Post Reply