Problem with Model-local complex variables - solved

Found a bug? Post information about it here so we can fix it!

Moderator: Moderators

User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Problem with Model-local complex variables - solved

Postby Rado1 » Thu Sep 01, 2016 8:58 pm

Model.Definitions can contain declarations of model instance-local variables. Everything goes fine when these local variables have simple type - float, int, string, ... The problem is when they are vec* or mat4. Then, they are not treated as local, but as global variables. See this example:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[model m = createModel(Model1);
m.Position.X = -5;
m.Variable1 = 1;
m.Variable2.X = 2;

m = createModel(Model1);
m.Position.X = 5;
m.Variable1 = 3;
m.Variable2.X = 4;]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <Content>
    <Model Name="Model1">
      <Definitions>
        <Variable Name="Variable1"/>
        <Variable Name="Variable2" Type="7"/>
      </Definitions>
      <OnRender>
        <RenderText TextFloatRef="Variable1" Y="0.9" Scale="10" UseModelSpace="255"/>
        <RenderText TextFloatRef="Variable2.X" Y="-0.9" Scale="10" UseModelSpace="255"/>
      </OnRender>
    </Model>
  </Content>
</ZApplication>

It should show:
1 3
2 4
,but shows:
1 3
4 4

User avatar
VilleK
Site Admin
Posts: 1883
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Problem with Model-local complex variables

Postby VilleK » Fri Sep 02, 2016 7:48 am

This is because these variable types hold references. When they are cloned they will have references to the same instance.
To force a new unique instance, use vector functions.

Try:

m.Variable2=vector2(1,2);

etc.

User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Re: Problem with Model-local complex variables

Postby Rado1 » Fri Sep 02, 2016 8:41 am

Thanks Ville for explanation. I did not realized "pointer nature" of var* variables.

BTW now, it necessary for each such a variable to create its own instance (i.e., to call variable2 = vector*() in OnSpawn section) when instantiating a Model. What about to do it automatically by ZGE? Do you think it would be helpful?

User avatar
VilleK
Site Admin
Posts: 1883
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Problem with Model-local complex variables

Postby VilleK » Fri Sep 02, 2016 11:39 am

It would be helpful if that was done automatically, yes. But so far I did not find a easy way to do this.


Return to “Bug reports”

Who is online

Users browsing this forum: No registered users and 1 guest