Digiverse Posted April 12, 2012 Share Posted April 12, 2012 Some game scripts refer to an objecttable in order to get additional info from an object created in its script. chassis=LoadModel("abstract::monstertruck.gmf") carobject=objecttable[chassis] car=carobject.vehicle In the above drive.lua game script, a monstertruck is being created in its own monstertruck.lua script when the gmf model is loaded and we can use the objecttable to get a reference to the vehicle object that was created in the monstertruck script. However, I'm a bit lost as to how I would get this vehicle object reference if I were to not have a game script but be running the game in C++. I could still use chassis=LoadModel("abstract::monstertruck.gmf") in my C++ game, but how could I get a reference to the vehicle object that was created by CreateVehicle in the monstertruck.lua? Sorry if this is basic stuff, but I'm a bit stumped! Thanks Quote Link to comment Share on other sites More sharing options...
ParaToxic Posted April 12, 2012 Share Posted April 12, 2012 I haven't programmed in lua yet but I think you can make that with the SetGlobalObject command and set the ObjectTable as a Object and get it in C++ Quote Link to comment Share on other sites More sharing options...
Daimour Posted April 12, 2012 Share Posted April 12, 2012 You can create your vehicle directly in C++. It means to convert entity script code to C++. So you will have access to all it's parts directly in C++. Quote Link to comment Share on other sites More sharing options...
smashthewindow Posted April 15, 2012 Share Posted April 15, 2012 If you main game is going to be in C++, I would suggest that you program every major part of the game (characters, events etc) in C++. Lua should be used to program smaller, additional behaviours (opening doors, etc). 1 Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Digiverse Posted April 16, 2012 Author Share Posted April 16, 2012 Thanks for your replies. My main reason for wanting to utilise Lua scripts for the basic setup and properties of the vehicle was so I could make quick changes during testing within the Editor environment and use the same script in my main c++ game. I was previously setting up my vehicle completely in C++, but it meant I wasn't easily able to use the same vehicle in the Editor (without copying the code into a lua script). I've still not found a way of accessing the TVehicle reference in C++ of a car made in Lua, but I've got around it quite well for now by doing everything that needs the TVehicle in the script and everything else in C++. In a way its quite nice because it keeps the creation and use of the vehicle seperate. Theres actually something quite satisfying about passing in throttle and steering commands from C++ into a car script and having the game control the car. I'm far more comfortable with C++ than Lua though and this only works for me at the moment because the code required in the car script is relatively small, so it maybe that long term I transfer it all back into C++ if I end up needing to access the TVehicle more, but the process has certinaly help me to learn Lua a bit. Quote 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.