How to use console.log(); for multiple variables

I am using p5.js and Kinectron to have one server computer display RGB, Depth, and Skeleton data from another computer over LAN, and it's own kinect.

Using p5.js, I am trying to log two different variables to the console, and I am only able to log one of the variables.

Code:

 ... function drawJoint(joint) { fill(100); console.log( "kinect1" + joint); // Kinect location data needs to be normalized to canvas size ellipse( ( joint.depthX * 300 ) + 400 , joint.depthY * 300 , 15, 15); fill(200); ... function draw2Joint(joint2) { fill(100); console.log ("kinect2" + joint2); // Kinect location data needs to be normalized to canvas size ellipse(joint2.depthX * 300 , joint2.depthY * 300, 15, 15); fill(200); ...

When running the above code, the console only shows Joint data from Kinect 1 in real-time, whereas I need both Kinect's Joint data to be logged to the Console.

How can I use console.log for multiple variables/arguments ?

Thanks in advance!

6

3 Answers

You will have to use global variables so that you can log them at the same time. Here are the lines of code to add into the functions that you have so far.

// add global variables
var joints1 = null;
var joints2 = null;
function bodyTracked(body) { // assign value to joints1 joints1 = body.joints;
}
function bodyTracked2(body) { // assign value to joints2 joints2 = body.joints;
}
function draw() { // log current values at the same time console.log(joints1, joints2);
}
0

Try this

var joint1,jointtwo;
function drawJoint(joint) { fill(100); joint1=joint; // Kinect location data needs to be normalized to canvas size ellipse( ( joint.depthX * 300 ) + 400 , joint.depthY * 300 , 15, 15); fill(200);
...
function draw2Joint(joint2) { fill(100); jointtwo=joint2; // Kinect location data needs to be normalized to canvas size ellipse(joint2.depthX * 300 , joint2.depthY * 300, 15, 15); fill(200); ... console.log(joint1+":"+jointtwo);
8

drawJoint and draw2Joint are called from somewhere so you can log joint and joint2 at that time.

console.log(joint,joint2);

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like