Page 1 of 1
condition check for number of models
Posted: Wed Sep 21, 2016 11:12 pm
by jinxtengu
Hi,
I'm a bit unsure how to write a condition which returns, how many instances of a certain type of model currently exist.
How is this done? Any ideas?
Re: condition check for number of models
Posted: Thu Sep 22, 2016 12:03 am
by Kjell
Hi junxtengu,
Maybe something like this ( left-click spawns a clone ) ?
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" ViewportRatio="3" FileVersion="2">
<OnUpdate>
<KeyPress Keys="{" RepeatDelay="0.25">
<OnPressed>
<ZExpression>
<Expression>
<![CDATA[Foo.Position.X = App.MousePosition.X*7.36;
Foo.Position.Y = App.MousePosition.Y*4.14;
createModel(Foo);]]>
</Expression>
</ZExpression>
</OnPressed>
</KeyPress>
</OnUpdate>
<OnRender>
<RenderText TextFloatRef="FooCount" X="-0.9" Align="1"/>
</OnRender>
<Content>
<Model Name="Foo">
<OnSpawn>
<ZExpression Expression="FooCount++;"/>
</OnSpawn>
<OnRender>
<RenderSprite/>
</OnRender>
<OnRemove>
<ZExpression Expression="FooCount--;"/>
</OnRemove>
</Model>
<Variable Name="FooCount"/>
</Content>
</ZApplication>
K
Re: condition check for number of models
Posted: Thu Sep 22, 2016 12:38 am
by jinxtengu
Thanks Kjell, but Isn't there another way of doing it without adding and subtracting from a variable when you spawn or remove a model?
Re: condition check for number of models
Posted: Thu Sep 22, 2016 2:36 pm
by Kjell
Hi,
jinxtengu wrote:Isn't there another way of doing it without adding and subtracting from a variable when you spawn or remove a model?
I'm afraid not ... the engine doesn't track this ( internally ), so you need to do-it-yourself.
K
Re: condition check for number of models
Posted: Fri Sep 23, 2016 1:16 am
by jinxtengu
That's good to know, and It gives me peace of mind. I thought I might have missed something in the documentation.