LUA script for seasonal textuers

Discussion related to terrain/scenery design.
Post Reply
MKMatt
Posts: 25
Joined: Sat Nov 23, 2013 11:51 pm
Location: Warsaw [PL]
Contact:

LUA script for seasonal textuers

Post 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
Mateusz Stabryla
MKSTUDIOS
ASUS Z370P, I9 9900K, RTX2080TI, 4 x 32GB DDR4 3200, W10
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: LUA script for seasonal textuers

Post 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.
Clifton Crane
Prepar3D® Software Engineer Sr.
MKMatt
Posts: 25
Joined: Sat Nov 23, 2013 11:51 pm
Location: Warsaw [PL]
Contact:

Re: LUA script for seasonal textuers

Post 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
Mateusz Stabryla
MKSTUDIOS
ASUS Z370P, I9 9900K, RTX2080TI, 4 x 32GB DDR4 3200, W10
MKMatt
Posts: 25
Joined: Sat Nov 23, 2013 11:51 pm
Location: Warsaw [PL]
Contact:

Re: LUA script for seasonal textuers

Post by MKMatt »

Hi,

Do you happen to have any idea about this?

I couldn't solve this out.

Thank you,
Mateusz Stabryla
MKSTUDIOS
ASUS Z370P, I9 9900K, RTX2080TI, 4 x 32GB DDR4 3200, W10
carlosgomez44
Posts: 3
Joined: Fri Feb 08, 2019 4:41 am

Re: LUA script for seasonal textuers

Post 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.
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: LUA script for seasonal textuers

Post 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)
Clifton Crane
Prepar3D® Software Engineer Sr.
Post Reply