如何使用 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 的关节数据,而我需要将两个 Kinect 的关节数据都记录到控制台。

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

提前致谢!

原文由 Jay Tailor 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 834
2 个回答

您将不得不使用全局变量,以便可以同时记录它们。以下是要添加到您目前拥有的功能中的代码行。

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

原文由 Rinay 发布,翻译遵循 CC BY-SA 4.0 许可协议

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

 console.log(joint,joint2);

原文由 NullPointer 发布,翻译遵循 CC BY-SA 4.0 许可协议

推荐问题