How to use JS callback node

01 June 2016 17:44
I'm trying to use the JSCalback node but i am not sure how to use it.

I tried using the ID in a manifold, the function name the function name with parentheses. None of it works. In the documentation i didn't find what the callback Id is.
here is the code i'm trying to triger


function setup_direction(){
var head = m_scenes.get_object_by_name("CubeHeadLeft");
var key_up = m_ctl.create_keyboard_sensor(m_ctl.KEY_T);
var key_down = m_ctl.create_keyboard_sensor(m_ctl.KEY_G);
var key_right = m_ctl.create_keyboard_sensor(m_ctl.KEY_H);
var key_left = m_ctl.create_keyboard_sensor(m_ctl.KEY_F);

var direction_array = [
key_up, key_down, key_right, key_left

var up_logic = function(s){return (s[0])};
var down_logic = function(s){return (s[1])};
var right_logic = function(s){return (s[2])};
var left_logic = function(s){return (s[3])};

function moveHead_cb(obj, id, pulse){

if (pulse == 1){
var head_pos = m_trans.get_translation(obj);
m_trans.set_translation(obj, head_pos[0], head_pos[1], head_pos[2]);
console.log("no pulse");;

m_ctl.create_sensor_manifold(head, "UP", m_ctl.CT_TRIGGER,
direction_array, up_logic, moveHead_cb);

Should i change this code to call movehead_cb?? What should i put in the node.

01 June 2016 17:56

This video from our recent conference may answer some of your questions
You should use the append_custom_callback method from "logic_nodes" module, instead of creating manifolds.
It takes two parameters: id for your callback and callback function itself. In the node you need two specify id, which you use in this method's call.
Blend4Web Team - developer
01 June 2016 18:30
Yeah of course! I hadn't realized they was a Logic_nodes module. My fault…
Thank you so much !
01 June 2016 18:35
Glad I could help
Blend4Web Team - developer
02 June 2016 13:08
You bet that was helpfull!
so i found that i works best by using the logic nodes module and this custom call
var m_logic_nodes= require("logic_nodes")

* callback executed when the app is initialized
function init_cb(canvas_elem, success) {

if (!success) {
console.log("b4w init failure");
m_logic_nodes.append_custom_callback("cubeClick", cubeClick);

* load the scene data
function load() {
m_data.load("LukeVideoLowPoly.json", load_cb);
function cubeClick(){

var vignette = document.getElementById('head');
if ( === "visible"){ = "hidden";
else { = "visible";


You will notice this is very primitive ! Yet it works !

Having great fun!

I was wondering how i could get Jquery call in function i call like that. I think i particular of the classtoggle i try to call on some DIV i position on top of the canvas? Maybe i should consider making my own module?

Have a great day !
07 June 2016 10:34
I am having trouble toggle the visibility again. I want my div to be hidden if i click again, no matter where. So i tried using the miss condition of my Switch select but nothing seems to happen.

Is the callback linked to an object or a successful click to be triggered?

Found a kind of Hack. It works if i SUCCESSFULLY click on a background object or the main character, not the trigger widget (that really should be a miss in my logic.).

It works because the scene is simple but if i had dozens of objects in the scene to check in a single switch select it wouldn't be very convenient.

Is there a meta object i could call like the screen or viewport? That way as soon as i click anywhere i could call the closing ( toggle ) function.

I am getting there thank you very much for all the effort. Wish i could of made it to the conference

Hopefully next year!
07 June 2016 11:04

Found a kind of Hack. It works if i SUCCESSFULLY click on a background object or the main character, not the trigger widget (that really should be a miss in my logic.).
Could you please attach a screenshot of your logic tree or blend file
Blend4Web Team - developer
07 June 2016 11:33
Yes of course!
There you go.
You will notice that the first switch select needs every object in the scene.

In my previous attempts i tried to link a miss to the JS callback but it doesn't seem to work.

Sorry pictures don't want to upload. There is the project.
07 June 2016 12:47

I want my div to be hidden if i click again, no matter where.
I think this simple configuration should work for you

Blend4Web Team - developer
07 June 2016 16:12
I tried this but my setup doesn't accept JsCallback from a miss… so i have to re-click on the same object to recall the function.

I tried all sort of Technics but a switch select miss never called the function of the JS callback on my machine. Maybe i could add a callback in JS waiting for a event listener waiting for a click event to occur? But i don't know what this would look like…

Have a nice day!

EDIT : Thinking about it… JS callback doesn't trust a Miss. What a Macho !
Please register or log in to leave a reply.