Jump to content

[SOLVED] Adding overloaded console commands


photo

Recommended Posts

Previously when using UnigineScript I was able to make console commands with overloaded callbacks quite easily.

 

Using the C++ API I am unable to create any sort of overload functionality and instead end up with 1 callback for each function which is messy.

 

What I want is a system that will take fw_lock_position, fw_lock_position 0, or fw_lock_position 1. How would I convert the following? Where do I specify my input arguments?

 

Unigine::CallbackBase * lockPositionCB = Unigine::MakeCallback(this, &FWOVehicle::LockVehiclePositionToggle);
Unigine::CallbackBase * lockOrientationCB = Unigine::MakeCallback(this, &FWOVehicle::LockVehicleOrientationToggle);
Unigine::Console::get()->addCommand("fw_lock_position", "Locks the Vehicles World Position", lockPositionCB);
Unigine::Console::get()->addCommand("fw_lock_orientation", "Locks the Vehicles World Rotation", lockOrientationCB);
 
Are there any examples of overloaded functions being added as console commands that I can reference?
 
Thanks.
Link to comment
engine.console.addCommand("lockPosition", "Locks the vehicle position.", "ConsoleLoad::LockPosition");

engine.console.addCommand("lockOrientation", "Locks the vehicle orientation.", "ConsoleLoad::LockOrientation");

 


void LockPosition(){}




void LockPosition(string var){}

 

When I try something similar in C++ API I am unable to get it to work.

 


 

Link to comment

Hi,

 

All callbacks, which you want to use as a console command, must have the same signature "The callback arguments must be (int,char**,...).", as you can see in our documentation.

I think this example helps you.

Unigine::Console::get()->addCommand("fw_lock_position", "Locks the Vehicles World Position", Unigine::MakeCallback(this, &FWOVehicle::LockPositionConsole));
void FWOVehicle::LockPositionConsole(int argc, char** argv) {
	for(int i = 0; i < argc; i++) {
		Unigine::Log::message("arg[%d]: %s\n",i,argv[i]);
	}
	// note: the first argument is the name of console command]
	if(argc == 1) {
		LockPosition();
	} else if(argc == 2) {
		LockPosition(argv[1]);
	} else if(...) {
		// etc
	}
}
void FWOVehicle::LockPosition(){}
void FWOVehicle::LockPosition(string var){}
Link to comment
×
×
  • Create New...