简体   繁体   English

谁能告诉我为什么我收到错误'无法读取未定义的属性'值''? P5.JS

[英]Can anyone tell me why i am getting the error 'Cannot read property 'value' of undefined'? P5.JS

I am coding a drawing app in which i am using constructor functions, my code is to try to get a hexagon to appear as a drawing tool.我正在编写一个使用构造函数的绘图应用程序,我的代码是尝试让六边形显示为绘图工具。 My issue is when i was trying to link it to another constructor function, it gives me the error我的问题是当我试图将它链接到另一个构造函数 function 时,它给了我错误

    Hexagon.js:27 Uncaught TypeError: Cannot read property 'value' of undefined
    at HexagonTool.draw (Hexagon.js:27)
    at draw (sketch.js:53)
    at e.d.redraw (p5.min.js:32)
    at e.<anonymous> (p5.min.js:31)

Does.value() not work as a constructor function? .value() 不能作为构造函数 function 工作吗? my code is split so all constructor functions are separate which link into a sketch and html file, i can post more code of other areas to help figure it out if need be.我的代码被拆分,因此所有构造函数都是分开的,它们链接到草图和 html 文件中,如果需要,我可以发布更多其他区域的代码以帮助弄清楚。 The code is below:代码如下:

function HexagonTool() {
  //set an icon and a name for the object
  this.icon = "assets/shapes.jpg";
  this.name = "shapes";

  var Hexagon;
  var HexagonSize;

  var HexagonSizeSlider;
  var nHexagonSlider;

  function preload() {
    Hexagon = loadImage('assets/Hexagon.png');
  }

  function setup() {
    HexagonSizeSlider = createSlider(5, 60, 20);
    HexagonSizeSlider.parent("#sizeOfHexagonControl");

    nHexagonSlider = createSlider(1, 25, 5);
    nHexagonSlider.parent("#numberOfHexagonsControl");
  }

  this.draw = function() {

    if (mouseIsPressed) {
      for (var i = 0; i < nHexagonSlider.value(); i++) {
        var HexagonSize = HexagonSizeSlider.value();
        var HexagonX = random((mouseX - HexagonSize / 2) - 25, (mouseX - HexagonSize / 2) + 25);
        var HexagonY = random((mouseY - HexagonSize / 2) - 25, (mouseY - HexagonSize / 2) + 25);
        image(Hexagon, HexagonX, HexagonY, HexagonSize,
          HexagonSize);
      }
    }
  }
}

I am looking at it, and this is after a few hours of trying to get it to work, i had two copies of preload and, removing the setup in the code above solved it我正在看它,这是在尝试让它工作几个小时之后,我有两个预加载副本,并且删除上面代码中的设置解决了它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谁能解释为什么我在Javascript中遇到此错误? [无法读取未定义的属性&#39;length&#39;] - Can anyone explain why I am getting this error in Javascript? [Cannot read property 'length' of undefined] 当我可以打印未定义的变量时,为什么会出现“无法读取未定义错误的属性”? - Why Am I Getting “Cannot read property of undefined error” When I Can Print the Undefined Variable? p5.j​​s 27646:未捕获的类型错误:无法读取未定义的属性“0” - p5.js 27646: Uncaught TypeError: Cannot read property '0' of undefined p5.j​​s上的“未捕获的TypeError:无法读取未定义的属性&#39;bind&#39;” - “Uncaught TypeError: Cannot read property 'bind' of undefined” on p5.js 无法读取函数中未定义的属性“0”(p5.js) - Cannot read property '0' of undefined in a function (p5.js) 为什么我越来越无法读取未定义错误的属性? - why I am getting, cannot read property of undefined error? 为什么我在 vue js 中收到“无法读取未定义的属性‘状态’”的错误 - why i am getting error of "cannot read property 'state' of undefined " in vue js 谁能告诉我如何在按下鼠标时触发一个函数并继续直到它在 p5.js 中被释放 - Can anyone tell me how to trigger a function when the mouse is pressed and continues untill it is released in p5.js p5.js 出现错误:未捕获的类型错误:无法读取 null 的属性“transpose3x3” - p5.js getting error: Uncaught TypeError: Cannot read property 'transpose3x3' of null 我正在尝试在 firebase 数据库上推送数据,但我收到此错误“无法读取属性“推送””,谁能告诉我我做错了什么? - I'm trying to push data on firebase database but I'm getting this error 'Cannot read property "push" ', can anyone tell me what I'm doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM