如何使用console.log();用于多个变量

时间:2018-07-23 17:05:25

标签: javascript json console console.log

我正在使用p5.js和Kinectron来使一台服务器计算机通过LAN从另一台计算机显示RGB,深度和骨架数据,这是它自己的kinect。

使用p5.js,我试图将两个不同的变量记录到控制台,而我只能记录其中一个变量。

代码:

   ...
    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);

      ...

运行上述代码时,控制台仅实时显示Kinect 1中的Joint数据,而我需要将Kinect的Joint数据都记录到控制台中。

如何将console.log用于多个变量/参数?

提前谢谢!

3 个答案:

答案 0 :(得分:2)

尝试一下

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);

答案 1 :(得分:1)

drawJointdraw2Joint从某个地方被调用,因此您可以log joint joint2

console.log(joint,joint2);

答案 2 :(得分:1)

您将必须使用全局变量,以便可以同时记录它们。这是到目前为止要添加到功能中的代码行。

// 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);
}