This page has been translated automatically.
Setting Up Development Environment
High-Level Systems
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
Double Precision Coordinates
Core Library
Engine Classes
Node-Related Classes
Rendering-Related Classes
Physics-Related Classes
Bounds-Related Classes
GUI-Related Classes
Controls-Related Classes
Pathfinding-Related Classes
Utility Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Constant Export

Constants are variables, the value of which does not change no matter what happens in C++ code. To be available in Unigine scripts, they need to be exported on C++ side.

  • External constants are read-only.
  • If a value of a registered constant is changed in the C++ code, on script side it will remain the same (unlike variables).

Constant Export Example

Constants are exported in the similar way as variables:

  1. Create a pointer to an external constant via MakeExternConstant().
  2. Register the constant via Unigine::Interpreter::addExternVariable().
  3. All variables are exported into a global namespace. To limit the scope of variable, use library namespace.
Source code(C++)
#include <UnigineEngine.h>
#include <UnigineInterpreter.h>

using namespace Unigine;

int main(int argc,char **argv) {

	int i = 0;
	float f = 0.0f;

	// export a variable and specify a name to access it from Unigine scripts
	// you can also specify a template parameter to make sure the proper type is passed
	Engine *engine = Engine::init(UNIGINE_VERSION,argc,argv);
	// enter the main loop
	while(engine->isDone() == 0) {
		// if a variable value is changed after it was registered, the value in scripts will not be changed
		i = 42;
		f = 57.55f;
	// engine shutdown 


Access from Scripts

After the registration, you can access constants from a script by their registered names:

Source code(UnigineScript)
// my_world.cpp

log.message("Integer: %d\nFloat: %f\n",int_constant,float_constant);


The following results will be printed into the console:

Integer: 0
Float: 0.000000

If you reload the world, the values of the constants that have been changed on the C++ side will remain the same.
Last update: 2017-07-03
Build: ()