MasteR Posted April 7, 2010 Share Posted April 7, 2010 (I reopened this thread in the C++ section as it is more appropriate) This topic will hopefully serve to educate me into where and how the Leadwerks engine implements LUA Scripts. I have spent a few days reading, analysing and testing various situations and I'm seeking confirmations and further education on the above topic. My questions are many and some (in my opinion) quite in depth but to get the ball rolling I'll start small. It is my understanding that the LoadModel() method will, amongst other things, search for an accompanying LUA script to the specified GMF model. So why does the following code not "Draw" the models "alignoncreate" onto the screen? and why is no light created (DebugLights() #include "engine.h" int main(int argc, char** argv) { Initialize(); Graphics(640,480); TWorld world = CreateWorld() ; TCamera camera = CreateCamera(); MoveEntity(camera,Vec3(0,0,-1)); TModel model = LoadModel("abstract::fixture_cagelight.gmf"); DebugLights(true); while(!KeyHit(KEY_ESCAPE)) { UpdateWorld(AppSpeed()); RenderWorld(RENDER_ALL); DrawText(0,0,"%s",GetEntityKey(model,"alignoncreate")); Flip(0); } Terminate(); return 1; } Quote AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz) 4 GB DDR2 RAM 2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB) Windows XP Pro Link to comment Share on other sites More sharing options...
Mumbles Posted April 7, 2010 Share Posted April 7, 2010 I don't know about lua scripting, but you need to call UpdateAppTime() before AppSpeed() currently the world is not being updated because AppSpeed() will keep returning 0. Possibly the reason that no lights are showing is because the world is not updating. You may not need to update the world for lights to be created, but I'm fairly sure that the lights will not be calculated if the world is not updated - After all, with no world updates, the engine does not know the positions of the objects to be illuminated. Also, where are you creating your light? In the script? If it's not in your script, then you have no code to create a light there. Quote LE Version: 2.50 (Eventually) Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 7, 2010 Share Posted April 7, 2010 Its been a while since I used c++ without Framework, but dont you need to set up buffers to render the lights ect. ? also the model in your code loads but needs to be turned 90 or 180 degrees to be seen: TModel model = LoadModel("abstract::fixture_cagelight.gmf"); RotateEntity(model,Vec3(0.0,90,0.0)); and make sure you have the "scripts" folder in your app directory. Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 7, 2010 Share Posted April 7, 2010 #include "engine.h" int main(int argc, char** argv) { Initialize(); Graphics(640,480); RegisterAbstractPath("YOUR PATH TO Leadwerks SDK 2.3"); TWorld world = CreateWorld() ; TBuffer gbuffer; gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL); TCamera camera = CreateCamera(); MoveEntity(camera,Vec3(0,0,-1)); TMesh ground; TMaterial material; material=LoadMaterial("abstract::cobblestones.mat"); TModel model = LoadModel("abstract::fixture_cagelight.gmf"); RotateEntity(model,Vec3(0.0,90,0.0)); ground=CreateCube(); ScaleEntity(ground,Vec3(10,1,10)); PositionEntity(ground,Vec3(0,-1,0)); PaintEntity(ground,material); DebugLights(true); while(!KeyHit(KEY_ESCAPE)) { // Update timing and world UpdateAppTime(); UpdateWorld(AppSpeed()) ; // Render SetBuffer(gbuffer); RenderWorld(); SetBuffer(BackBuffer()); RenderLights(gbuffer); DrawText(0,0,"%s",GetEntityKey(model,"alignoncreate")); Flip(0); } Terminate(); return 1; } Make sure you have the scripts folder in your app directory's root. Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
MasteR Posted April 8, 2010 Author Share Posted April 8, 2010 Make sure you have the scripts folder in your app directory's root. That’s what it was. The "directory's root" is the same location as the executable, and not the location of the source files as I had mistakenly thought. Very much appreciated. Next question: I'm hoping to gain a better understanding of how "integrated" the use of LUA scripts is in the Leadwerks engine. I'm aware of its use in the LoadModel() command, and the combined use of Engine.exe and the script editor, but how "integrated" is it? A practical example derived from the above code. Say I rename the fixture_cagelight.lua to simply cagelight.lua, The LoadModel() command will fail to locate an accompanying LUA script and therefore the script is not run. The program then enters a loop waiting for the user pressing the "Q" key. Upon pressing the "Q" key how would I then get the program load and run cagelight.lua? Quote AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz) 4 GB DDR2 RAM 2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB) Windows XP Pro Link to comment Share on other sites More sharing options...
MasteR Posted April 15, 2010 Author Share Posted April 15, 2010 No ideas on my new question? Quote AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz) 4 GB DDR2 RAM 2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB) Windows XP Pro Link to comment Share on other sites More sharing options...
ZioRed Posted April 15, 2010 Share Posted April 15, 2010 Really I don't know and never tried that (cannot see how it may be useful since generally in a game you have GMF models for everything and so why just don't simply use the standard way?), but I think that loading a specific script for an entity other than the default way (file named same as GMF model) is not possible... But I am newbie (or less) in lua scripting, so I may be in fault. However I've found this example in which the author loads a lua script from C++ Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
MasteR Posted April 15, 2010 Author Share Posted April 15, 2010 Really I don't know and never tried that (cannot see how it may be useful since generally in a game you have GMF models for everything and so why just don't simply use the standard way?), but I think that loading a specific script for an entity other than the default way (file named same as GMF model) is not possible... But I am newbie (or less) in lua scripting, so I may be in fault. However I've found this example in which the author loads a lua script from C++ I agree that my given example is out of the ordinary and strictly pointless so I shall reword it, identifying the same premise but in a more likely application. Say I have a simple program that loads "tunnels.sbx" and enables simple camera movement. After the player enters the first room on the map I want an in game cut scene to play. This cut scene is written in and controlled entirely by a LUA script. So the question remains how is one to load and execute a LUA script under the above circumstances? (Thinking on this I will examine “switch.lua”) I've looked at many LUA examples and I don't mind adding the LUA dll's to my project but LUA is "integrated" into the Leadwerks engine and the above functionality may already be available without having to add the LUA dll's, or it may not. So my question remains Quote AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz) 4 GB DDR2 RAM 2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB) Windows XP Pro Link to comment Share on other sites More sharing options...
Josh Posted April 16, 2010 Share Posted April 16, 2010 There is no mechanism to execute an arbitrary Lua script, other than using the Lua command set yourself to do so. There is a command to retrieve the handle of the global lua state the engine uses for script execution, and this can be used with the native Lua command set in a C++ project. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
MasteR Posted April 16, 2010 Author Share Posted April 16, 2010 Cheers Quote AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz) 4 GB DDR2 RAM 2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB) Windows XP Pro Link to comment Share on other sites More sharing options...
Recommended Posts
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.