Jump to content

ObjectTable in C++ ?


Digiverse
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

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...