Page 1 of 1

Assigning a bitmap to MaterialTexture.Bitmap from an array

Posted: Tue May 17, 2016 9:11 am
by rrTea
Pressing 1 works, but 2 and 3 do not. What am I missing?

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZLibrary Comment="Bitmaps">
      <Source>
<![CDATA[Bitmap[4] arr_OverworldLocations;

arr_OverworldLocations[1] = bmp_OverLoc01;
arr_OverworldLocations[2] = bmp_OverLoc02;
arr_OverworldLocations[3] = bmp_OverLoc03;]]>
      </Source>
    </ZLibrary>
  </OnLoaded>
  <OnUpdate>
    <KeyPress Comment="1" Keys="1" RepeatDelay="0.2">
      <OnPressed>
        <ZExpression Expression="matTex_Material1.Texture = bmp_OverLoc01; //arr_OverworldLocations[1];"/>
      </OnPressed>
    </KeyPress>
    <KeyPress Comment="2" Keys="2" RepeatDelay="0.2">
      <OnPressed>
        <ZExpression Expression="matTex_Material1.Texture = arr_OverworldLocations[2];"/>
      </OnPressed>
    </KeyPress>
    <KeyPress Comment="3" Keys="3" RepeatDelay="0.2">
      <OnPressed>
        <ZExpression Expression="matTex_Material1.Texture = arr_OverworldLocations[3];"/>
      </OnPressed>
    </KeyPress>
  </OnUpdate>
  <OnRender>
    <UseMaterial Material="Material1"/>
    <RenderNet>
      <RenderVertexExpression>
<![CDATA[//Update each vertex.
//Vertex : current vertex
//TexCoord : current texture coordinate
//Color : current vertex color

Vertex *= 2;]]>
      </RenderVertexExpression>
    </RenderNet>
  </OnRender>
  <Content>
    <Material Name="Material1">
      <Textures>
        <MaterialTexture Name="matTex_Material1" Texture="bmp_OverLoc01" TextureWrapMode="2" TexCoords="1"/>
      </Textures>
    </Material>
    <Bitmap Name="bmp_OverLoc01" Width="128" Height="128" Filter="1">
      <Producers>
        <BitmapCells UsedMetrics="4" RandomSeed="48"/>
      </Producers>
    </Bitmap>
    <Bitmap Name="bmp_OverLoc02" Width="128" Height="128" Filter="1">
      <Producers>
        <BitmapCells UsedMetrics="4"/>
      </Producers>
    </Bitmap>
    <Bitmap Name="bmp_OverLoc03" Width="128" Height="128" Filter="1">
      <Producers>
        <BitmapCells UsedMetrics="4" RandomSeed="37"/>
      </Producers>
    </Bitmap>
  </Content>
</ZApplication>

Re: Assigning a bitmap to MaterialTexture.Bitmap from an array

Posted: Tue May 17, 2016 10:01 am
by Kjell
Hi rrTea,
rrTea wrote:What am I missing?
You can't initialize a array like that from a ZLibrary. Copy the "arr_OverworldLocations[X] = bmp_OverLoc0X;" lines to a ZExpression in OnLoaded and it will work.

K

Re: Assigning a bitmap to MaterialTexture.Bitmap from an array

Posted: Tue May 17, 2016 10:56 am
by VilleK
Ah, yes that shouldn't compile :). A ZLibrary can only hold function, variable, and constant declarations. Not actual code. So keep the array declaration in the ZLibrary and move the code into ZExpression instead like Kjell suggests.

Re: Assigning a bitmap to MaterialTexture.Bitmap from an array

Posted: Tue May 17, 2016 11:41 am
by rrTea
Ouch yeah... right, thanks, how did I manage to paste it there (ZExpression and ZLibrary really look too similar!) - what a stupid mistake on my part :D

Re: Assigning a bitmap to MaterialTexture.Bitmap from an array

Posted: Fri Jun 10, 2016 6:32 am
by rrTea
Here's one other thing that looks to me like it shouldn't compile:

Code: Select all

if (BattleOrigin == 0)
{
BattleChain++;
CurrentRoom = arr_BattlesList[BattleChain];
CurrentLevel = AreaCurrent;
StateSwitch.State = state_Battle;} //note there's an extra curly bracket in this line
}

else
{
StateSwitch.State = state_SelectGame;
}

Shouldn't compile?

Posted: Sat Aug 13, 2016 8:22 am
by rrTea
Here is another thing that I think shouldn't compile after being pasted in a fresh project, this one has a typo and a misnamed property but when compiling it nothing is reported:

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<ZExpression>
  <Expression>
<![CDATA[vec3[2] ColTable;?
ColTable[0] = vector3(255f/255, 128f/255, 0); //orange
ColTable[1] = vector3(1, 1, 1); //white

int T, T1, T2;
T = round(frac(Prg.Time));
T1 = 0+T;
T2 = 1-T;

trace (
"Current: " + intToStr(T1) + ", " + intToStr(T1)
);

//setCol_pointer1.Color = ColTable[T1];
//setCol_pointer2.Color = ColTable[T2];]]>
  </Expression>
</ZExpression>
This was copied from a project whose name is "Prg" (as opposed to the default "App"), so in a fresh project (that uses "App") "Prg.Time" should trigger a warning?...
Another thing is, even if you fix it to "App.Time" (or rename the project to "Prg"), nothing will be traced in the console.

The typo is in the first line:

Code: Select all

vec3[2] ColTable;?
there's a question mark at the end... this doesn't get reported when compiling.

Obviously these mistakes are on my end, but this should trigger an error report I think?

Re: Assigning a bitmap to MaterialTexture.Bitmap from an array

Posted: Sat Aug 13, 2016 8:47 am
by VilleK
Indeed it seems that the incorrect "?" makes the parser ignore everything afterwards. That should be fixed.