condition check for number of models

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

condition check for number of models

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

Re: condition check for number of models

Post 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
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

Re: condition check for number of models

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

Re: condition check for number of models

Post 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
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

Re: condition check for number of models

Post by jinxtengu »

That's good to know, and It gives me peace of mind. I thought I might have missed something in the documentation.
Post Reply