簡體   English   中英

如何使用console.log(); 對於多個變量

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

我正在使用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用於多個變量/參數?

提前致謝!

嘗試這個

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

從某個地方調用了drawJointdraw2Joint ,因此您可以在那時log jointjoint2

console.log(joint,joint2);

您將必須使用全局變量,以便可以同時記錄它們。 這是到目前為止您要添加到函數中的代碼行。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM