5

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!

7
  • 3
    Do you know if draw2Joint is being executed? Commented Jul 23, 2018 at 17:08
  • 4
    console.log(var1, var2, var3); Commented Jul 23, 2018 at 17:09
  • Please provide a running code so that anyone can debug it and let you know where it lacks. Commented Jul 23, 2018 at 17:09
  • Yes, draw2joint is being executed, I know this because when I dont use and console.log(); lines, I can see the Skeleton from 2 kinects on one computer, meaning that function must be working. Commented Jul 23, 2018 at 17:11
  • @NullPointer , would I use console.log(var1, var2, var3); inside the function or outside it? Commented Jul 23, 2018 at 17:12

3 Answers 3

11

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);
}
Sign up to request clarification or add additional context in comments.

Comments

4

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

console.log(joint,joint2);

Comments

2

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 Comments

Does it matter where the last line,. console.log(joint1+ ":" +jointtwo); goes? Would it be after all the functions or inside a function
joint1,jointtwo are global variables so you can get the values
If it is not working...make jsfiddle and send me your full code..i will edit it
We are getting undefined:undefined in the console. However, we have been using p5.js editor online and as an application. jsfiddle.net/jaytailor15/koLr3zhm/#&togetherjs=KD8zH2atFf
Check your function calling or not?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.