Jump to content

Lua for Models Tutorial?


NivorbiaN
 Share

Recommended Posts

As there is no LUA section on the wiki, and LUA being such a big part of LE, is there some tutorial on, how LUA model files should be.

 

i am looking at the LUA files that come along with the models supplied with LE, but there is no explanation.

 

the only explanation i could find was in the "Leadwerks 2.3 - User Guide - 1.01"

 

it said :

require("scripts/class")

local class=CreateClass(...)

*For an exact explanation of what this script does, please ask on the forum

 

with other words, what is the correct syntax of LUA for model files.

 

i looked at some tutorials on LUA but non explain the usage with LE, they just explain the LUA language, i just want to make LUA files for models, not script or program in LUA in any way.

"Hmm, don't have time to play with myself." ~Duke Nuke'm

Link to comment
Share on other sites

Those 2 lines:

require("scripts/class")
local class=CreateClass(...)

are needed for every model, because without those many things don't even work. For example entitykeys in a model's ini file are not read in.

You don't usually need anything else in the Lua file than those 2 lines.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

thanks you two, now i know what the basics are.

 

so i made an object to store the fog settings and a LUA file like this:

 

/////////////////////////////////////////////////////////////////////////

 

require("scripts/class")

 

local class=CreateClass(...)

 

function class:InitDialog(grid)

self.super:InitDialog(grid)

group=grid:AddGroup( "FogSetting" )

group:AddProperty( "FogOnOff", PROPERTY_BOOL)

group:AddProperty( "FOG_R", PROPERTY_FLOAT,'|0.0,1.0,1' )

group:AddProperty( "FOG_G", PROPERTY_FLOAT,'|0.0,1.0,1' )

group:AddProperty( "FOG_B", PROPERTY_FLOAT,'|0.0,1.0,1' )

group:AddProperty( "FOG_A", PROPERTY_FLOAT,'|0.0,1.0,1' )

 

group:AddProperty( "FogAngleB", PROPERTY_FLOAT,'|0.0,90,1' )

group:AddProperty( "FogAngleE", PROPERTY_FLOAT,'|0.0,90,1' )

 

group:AddProperty( "FogRangeB", PROPERTY_FLOAT,'|0.0,5000,1' )

group:AddProperty( "FogRangeE", PROPERTY_FLOAT,'|0.0,5000,1' )

group:Expand(1)

end

 

function class:CreateObject(model)

local object=self.super:CreateObject(model)

object.model:SetKey("FogOnOff","1")

object.model:SetKey("FOG_R","1")

object.model:SetKey("FOG_G","1")

object.model:SetKey("FOG_B","1")

object.model:SetKey("FOG_A","1")

 

object.model:SetKey("FogAngleB","0")

object.model:SetKey("FogAngleE","45")

 

object.model:SetKey("FogRangeB","0")

object.model:SetKey("FogRangeE","10")

end

 

//////////////////////////////////////////////////////////////

 

 

can I just use: group=grid:AddGroup( "FogSetting" )

or are there predefined groupnames?

are there reserved group names?

 

it does seem to work though, but i am afraight to use names that are not to be used.

 

thanks for the help!

"Hmm, don't have time to play with myself." ~Duke Nuke'm

Link to comment
Share on other sites

If you open class.lua in your Scripts folder you can see the default groups. I don't know LUA very well but may be you have a grid:GetGroup besides to grid:AddGroup. But in my opinion for your own model it should be more handy to have your own property groups for rapidly access them from editor's UI.

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

I never used one of the default class groupnames before, so I don't know for sure. But since you create a new class it takes those groupnames and properties from class.lua. Thats why I think that it can not harm if you use the same groupnames.

 

I still would recommend using your own groupname, to prevent confusion.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...