Blend4Web API Reference

Adding Modules

Use b4w.register(module_name, module_body) to create your own modules.

Example - Registering a Module:

// check if the module already exists
if (b4w.module_check("my_module"))
    throw "Failed to register my_module";

// register my_module
b4w.register("my_module", function(exports, require) {

    // import a Blend4Web module
    var m_version = require("version");

    // create and export your own method
    exports.print_build_date = function() {

        // use a Blend4Web method
        console.log("Engine build date: " + m_version.date());

Example - Using the Registered Module:

// import the module
var m_my_module = b4w.require("my_module");

// use a module's method