无法弄清楚为什么在p5.js中未定义变量 [英] Cannot Figure out Why Variable is Undefined in p5.js

查看:67
本文介绍了无法弄清楚为什么在p5.js中未定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信这是有史以来最简单的问题,但是我和我的朋友正在用p5.js进行成对编码,我们不明白为什么下面的代码会抛出错误:unautrutReferenceError:没有定义RiLicion

我们做过一个类似的项目,所有代码基本上都在完全相同的位置,而且可以正常工作。也许我们盯着这个看了太久,快要疯了?请帮帮我!谢谢!

var mermaid = ("Fishes, both large and small, glide between the branches, as birds fly among the trees here upon land. In the deepest spot of all, stands the castle of the Sea King. Its walls are built of coral, and the long, gothic windows are of the clearest amber. The roof is formed of shells, that open and close as the water flows over them. Their appearance is very beautiful, for in each lies a glittering pearl, which would be fit for the diadem of a queen.");
var story = []; 
var lexicon;


function setup() {

    createCanvas(650,400);
    lexicon = new RiLexicon();
    story = RiTa.tokenize(mermaid);
    //partsOfSpeech = RiTa.getPosTags(story);
    textSize(15);
    fill(255, 100, 100);


function draw(){
 // background(255);

 var wordPosX = 10;
var wordPosY = width/8;


    for(var i=0; i < story.length; i++){
      text(story[i], wordPosX, wordPosY)
      textWidth(story[i]+5,30);

      //we check whether each parts of speech exists
      //in our array
      //if(partsOfSpeech[i] != null){
      //  text(partsOfSpeech[i], wordPosX, wordPosY+20, textWidth(story[i]), 20);
     // fill(100,175,175);  


      wordPosX += textWidth(story[i])+ 3;

      //if wordPosX goes beyond our width,
      //move the text down to a new line
      if(wordPosX +30 > width){
        wordPosX = 10;
        wordPosY += 50;
      }
    }
}
      function mousePressed(){
        changingWords();
        textSize(15);

        function changingWords (){
        var story = "Fishes," + 
          lexicon.randomWord("nn") + "" + 
          lexicon.randomWord("jj") + 
          "and" + lexicon.randomWord("jj") + 
          ", glide between the branches, as birds fly among the trees here upon" + 
          lexicon.randomWord("nn") + 
          ". In the deepest" + lexicon.randomWord("nn") + 
          "of all, stands the" + lexicon.randomWord("nn") + 
          "of the Sea King. Its walls are built of" + 
          lexicon.randomWord("jj") + 
          ", and the" + lexicon.randomWord("jj") +
          "," + lexicon.randomWord("jj") + 
          "windows are of the clearest" + 
          lexicon.randomWord("jj") + 
          ". The" + lexicon.randomWord("nn") + 
          "is formed of shells, that" + 
          lexicon.randomWord("jj") + 
          "and close as the" + 
          lexicon.randomWord("nn") + 
          "flows over them. Their" + 
          lexicon.randomWord("nn") + 
          "is very" + lexicon.randomWord("jj") + 
          ", for in each lies a glittering" + 
          lexicon.randomWord("nn") + 
          ", which would be fit for the" + 
          lexicon.randomWord("nn") + 
          "of a queen."
        }  
    }
 }

推荐答案

正如评论所说,您需要确保加载的是RITA库。

听起来可能您之前的草图已经加载库,然后您将该草图中的一些代码复制到新的草图中。问题是,这还不足以让你的新草图发挥作用。您必须将库加载到新草图中,以便可以访问它。

Here是关于如何加载库的非常棒的教程,但我将尝试将基础知识复制到这里:

第1步:here下载RITA。

第二步:查找名为rita-full.min.js的文件(也可以直接从here下载)。

第3步:将该文件复制到草图目录中。您的html文件应该可以访问它。

步骤4:编辑html文件以加载库,方法是将此行放入<head>部分:

<script src="your/path/to/rita-full.min.js" type="text/javascript"></script>

第5步:现在,当您加载html页时,库将被加载,并且您的代码将能够访问它。

您可以在RiTaJS的GitHub页面herethis RiTaJS tutorial中找到更多信息。

这篇关于无法弄清楚为什么在p5.js中未定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆