Page 1 of 1

LUA script for seasonal textuers

Posted: Thu Oct 18, 2018 12:39 pm
by MKMatt
Hi,

I've been trying to add LUA script to my scenery. However the final result is that the material is not visible.

Here's what I've done:
!lua
local month = varget("E:ZULU MONTH OF YEAR", "Number")
local StringOld = varget("T:DiffuseTexture", "String")
local StringNew
if month > 9 then
StringNew=string.sub(StringOld,1,12) .. "_WI.DDS"
elseif month > 8 then
StringNew=string.sub(StringOld,1,12) .. "_FA.DDS"
elseif month > 5 then
StringNew=string.sub(StringOld,1,12) .. ".DDS"
else
StringNew=string.sub(StringOld,1,12) .. "_WI.DDS"
end
varset("T:DiffuseTexture","String",StringNew)
Then I've created another folder 'scripts' with 'texture' folder inside. I moved LUA and textures there that should be used by my object.

Image

Image

I want to keep the scripts in my project folder, I also added the entry to add-on.xml so it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<SimBase.Document Type="AddOnXml" version="4,0" id="add-on">
<AddOn.Name>Airport test</AddOn.Name>
<AddOn.Description>Airport</AddOn.Description>
<AddOn.Component>
<Category>Scripts</Category>
<Path>scripts</Path>
</AddOn.Component>
<AddOn.Component>
<Category>Effects</Category>
<Path>effects</Path>
</AddOn.Component>
<AddOn.Component>
<Category>Scenery</Category>
<Path>scenery</Path>
<Name>Airport scenery</Name>
</AddOn.Component>
<AddOn.Component>
<Category>Texture</Category>
<Path>texture</Path>
<Type>WORLD</Type>
</AddOn.Component>
<AddOn.Component>
<Category>Texture</Category>
<Path>scripts\texture</Path>
<Type>GLOBAL</Type>
</AddOn.Component>
</SimBase.Document>
I also tried to put them into P3D main/Scripts folder to check however result remain the same - material is not visible, but BGL is loaded.

I tried to follow the SDK here, however I can't find any other tips for this.

Kind regards,
Matt

Re: LUA script for seasonal textuers

Posted: Thu Oct 18, 2018 9:29 pm
by Clifton Crane
Hi Matt,

Do you have any Content Errors being reported? This setting first needs to be enabled, then the ContentErrorReport.txt file will be output to your Documents\Prepar3D v4 Files directory.

Thanks.

Re: LUA script for seasonal textuers

Posted: Fri Oct 19, 2018 8:13 am
by MKMatt
Hi!

Thank you for quick reply.

I checked content errors and there's one message related to the texture:
[error.27]
error=Texture GRASS_3D.DDS.DDS failed to load (FE_REQUEST_STATUS==13)
There seems to be a problem in the file extension being added twice to the file name. I modified texture name in BGL file and removed .DDS from it but it didn't solve the case.

Kind regards,
Matt

Re: LUA script for seasonal textuers

Posted: Tue Oct 30, 2018 10:18 am
by MKMatt
Hi,

Do you happen to have any idea about this?

I couldn't solve this out.

Thank you,

Re: LUA script for seasonal textuers

Posted: Fri Feb 08, 2019 4:48 am
by carlosgomez44
Hi Matt. I am doing some wet ground when raining and my LUA script is similar. My issue is that it doesn't seem to read de correct language. In the ContentError all the lines are reporting:
error=Gauge/Script ErrorType=UnknownName: UnknownError: Invalid Script (comand not found...)
Im exporting from 3dsMax with 4.4 SDK and attaching the materialScript as intended in the material properties. There's some special workflow in order to make it read the LUA script as script? Thanks.

Re: LUA script for seasonal textuers

Posted: Mon Feb 11, 2019 3:29 pm
by Clifton Crane
Hi carlosgomez44,

It sounds like your script may have some syntax and compile errors. Does your script start with !lua on the first line? There is a sample material script in your Prepar3D application "Scripts" directory called "Material Season Example.lua". It shows how to change diffuse color based on the month of the year:
!lua

-- Material Season Example.lua
-- An example script demonstrating changing a material's
-- diffuse color based on the month of the year.

local colorRed = 1.0
local colorGreen = 1.0
local colorBlue = 1.0

local month = varget("E:ZULU MONTH OF YEAR", "Number")

if month > 3 then
colorRed = 0.0
end

if month > 6 then
colorGreen = 0.0
end

if month > 9 then
colorBlue = 0.0
end

varset("T:DiffuseColorRed","Number",colorRed)
varset("T:DiffuseColorGreen","Number",colorGreen)
varset("T:DiffuseColorBlue","Number",colorBlue)