Category changing unexpected effect

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Category changing unexpected effect

Post by rrTea »

I'm trying to make a Model (spawned as Category 1) spawn a copy of itself and then flip its category to 2. But what happens is that all the new models are spawned as Category 2 models. Why is that?

For example I'd expect this code to have one green rectangle (the freshly spawned one) and if there are any other Models they should be fuchsia, but there are no green models after the first spawn is triggered:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="Model2" Position="-4 0 0" UseSpawnerPosition="255"/>
  </OnLoaded>
  <Content>
    <Model Name="Model2" Scale="0.25 0.25 1" Category="1">
      <OnUpdate>
        <Timer Interval="1" RepeatCount="0">
          <OnTimer>
            <ZExpression Expression="CurrentModel.Category = 2;"/>
            <SpawnModel Model="Model2" Position="1 0 0" UseSpawnerPosition="255"/>
          </OnTimer>
        </Timer>
      </OnUpdate>
      <OnRender>
        <Condition Comment="1 (green)" Expression="return(CurrentModel.Category == 1);">
          <OnTrue>
            <UseMaterial Material="Material1"/>
            <RenderSetColor Color="0 1 0.251 1"/>
            <RenderNet>
              <RenderVertexExpression>
<![CDATA[//Update each vertex.
//Vertex : current vertex
//TexCoord : current texture coordinate
//Color : current vertex color

Vertex *=4;]]>
              </RenderVertexExpression>
            </RenderNet>
          </OnTrue>
        </Condition>
        <Condition Comment="2 (fuchsia)" Expression="return(CurrentModel.Category == 2);">
          <OnTrue>
            <UseMaterial Material="Material1"/>
            <RenderSetColor Color="1 0 0.502 1"/>
            <RenderNet>
              <RenderVertexExpression>
<![CDATA[//Update each vertex.
//Vertex : current vertex
//TexCoord : current texture coordinate
//Color : current vertex color

Vertex *=4;]]>
              </RenderVertexExpression>
            </RenderNet>
          </OnTrue>
        </Condition>
      </OnRender>
    </Model>
    <Material Name="Material1" Shading="1" Light="0"/>
  </Content>
</ZApplication>
If I force it back to Category 1 in the OnSpawn

Code: Select all

CurrentModel.Category = 1;
it behaves as I'd expect it to, but I still don't understand why does it need to be forced?
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Category changing unexpected effect

Post by VilleK »

With the CurrentModel.Category assignment you change the original model category. Then from now on every clone will have that category too.

Better do something like this:

Model m=createModel(Model2);
m.Category=2;
Post Reply