Forum

looping in the wrong section

30 July 2018 14:50
Hello so i have made a custom sin wave visualizor.
I use js callback nodes, but i made a loop in the node editor and it keep looping the wrong function.

here the logic nodes :


and here the js code:

function init_cb(canvas_elem, success) {

   [...]

	m_logic.append_custom_callback("addMeSomeCubes", addMeSomeCubes);
	m_logic.append_custom_callback("movingTime", movingTime);

    load();
}


function addMeSomeCubes()
{
	var nbOfCube = document.getElementById("readMe");

	var spaceBetweenCube =  10 / nbOfCube.value;

	for(var i = 0; i < nbOfCube.value; i++)
	{
		var cube = m_scenes.get_object_by_name("Cube");
		var new_obj = m_obj.copy(cube, "Cube_" + i, true);

		m_scenes.append_object(new_obj);
		m_transform.set_translation(new_obj, 0, -5 + spaceBetweenCube*i*5, Math.sin(-5 + spaceBetweenCube*i)*5);
		m_scenes.show_object(new_obj);
		arrayOfCube.push(new_obj);

		//m_mat.inherit_material(cube, "Based_on_high", new_obj, "Based_on_high");
	}

	console.log(arrayOfCube);
	return document.getElementById("myCheck").checked;
}

var add = 1;

function movingTime()
{
	console.log("MOVING");

	for( var i = 1; i < arrayOfCube.length; i++)
	{
		m_transform.set_translation(arrayOfCube[i], 0, -5 + spaceBetweenCube*i*5, Math.sin(-5 + spaceBetweenCube*i + add)*5);
	}

	add += 1;

	return document.getElementById("myCheck").checked;
}


why is it looping trough the same function all the time, i don't understand. i can share the full projet if you want.
30 July 2018 21:01
The principal animation works, but you have several errors in your script, for example, "spaceBetweenCube" is defined locally in "addMeSomeCubes", so the "moving" function would crash if called but it won't be called because your logic tree doesn't work. You try to work with OutParams, but OutParams are passed through the arguments[] array, not through return values.

Maybe you could describe the details of what you want to achieve? As I see it, you have an object "Plane" and when the user clicks it, a (probably user-selectable) number of cubes is generated to make up a sine curve which is then animated. Do you want the animation to stop after 100 iterations? Or when the user checks a checkbox? It's hard to tell mainly because I don't see the customization buttons the user has. You need to describe this precisely or attach/link to your project.
31 July 2018 11:36
Oh ok for the out argument, I've read the doc but did not find that. The is a tutorial video on youtube but I dit not fully understand why the is in and out params in the function. I get it now!

here the project, it a change a bit. but yes my goal is to make the thing move while the checkbox is checked. and the user choose the number of cube he want, maybe it will change in the futur to line instead of cube.


https://ufile.io/1znhc
31 July 2018 18:07
Hello everyone, the problem is now solved, i had to rewritting a bit of the code and change the logic node order by adding a button. I will share soon the archive for everyone to use.

Huge thanks to blend4life
01 August 2018 00:15
I made a version with sliders instead of inputs, for what it's worth:

LINK
24 August 2018 17:03
so here the final projet :

green is for creation the graph

red deleting

blue is for running the graph after checking the box make it alive
 
Please register or log in to leave a reply.