The Grit console is an extremely powerful tool. One can use it to reload/update assets, debug/inspect values, hack in changes in realtime, and even write arbitrarily complicated programs. It is powered by Lua. A little knowledge of Lua can make your use of Grit a lot more efficient. Here are some trivial examples.

Reload a Lua script

Make a change in the script and then do:

 lua> include "my_dir/my_script.lua"

Reloading Assets

To reload a whole class, point at an object of that class (it must have a physics representation) and do:


The pick_obj() is instructing the console to use the object being pointed at by the crosshair. You can also use player_ctrl.vehicle instead of pick_obj() to fetch the car that you're currently driving. You can use streamer:getObject("the_name") to refer to an instance by its name. This can be useful for objects that have no TCOL You can get a list of objects with:

 lua> streamer.objects

To reload a particular texture:

 lua> get_texture("top_gear/Track.dds"):reload()

To reload a particular mesh:

 lua> get_mesh("top_gear/Track.mesh"):reload()

To reload a particular collision mesh:

 lua> pw:getMesh("top_gear/Track.tcol"):reload()

To reload materials, just include the Lua file containing the material definitions again.

Note, you can also reload meshes from an object. Reload graphics mesh:

 lua> pick_obj().instance.entity.mesh:reload()

And reload the tcol:

 lua> pick_obj().instance.body.mesh:reload()

Inspect/modify a value

Point at a car and then do

 lua> pick_obj().instance.wheels[1].suspensionLength

 lua> pick_obj().instance.wheels[1].suspensionLength = 0.5

Apply a force

 lua> pick_obj().instance.body:impulse(Vector3(0,0,100))

Destroy an object

 lua> pick_obj():destroy()

If you want the object to simply respawn (for objects that do respawn):

 lua> pick_obj():deactivate()

Get a list of classes/objects in the scene

 lua> streamer.classes
 lua> streamer.objects

Clear all classes/objects in the scene

 lua> streamer:clearClasses()
 lua> streamer:clearObjects()

You can also clear all the objects that were not given explicit names (i.e. they are called 'unnamed32' or similar). This can be useful to avoid getting duplicate objects when reloading a map Lua file.

 lua> streamer:clearAnonymousObjects()

Finding out positions

To get the current camera position when ghosting around:

 lua> gfx.camPos.position

To get the distance of the point aimed at:

 lua> pick_dist()

To get the position of the point aimed at:

 lua> pick_pos()

To find the distance between 2 points, record the 2 points as follows

 lua> v1 = pick_pos()
 lua> v2 = pick_pos()

Then you can subtract the two vectors as follows:

 lua> v2-v1

If you want the actual distance, then do:

 lua> #(v2-v1)

To get the position of an object, do:

 lua> pick_obj().instance.body.worldPosition

To get the spawn location, do:

lua> pick_obj().spawnPos