tmorris Posted April 19, 2016 Share Posted April 19, 2016 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
silent Posted April 19, 2016 Share Posted April 19, 2016 Hi Taylor,May I ask how did you manage to solve this on UnigineScript side (just to have the main idea)?Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
tmorris Posted April 19, 2016 Author Share Posted April 19, 2016 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
futurist Posted April 20, 2016 Share Posted April 20, 2016 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
tmorris Posted April 20, 2016 Author Share Posted April 20, 2016 Thank you, this is exactly what I was looking for. Link to comment
Recommended Posts