Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

well, it is javascript, so you could implement something like https://stackoverflow.com/questions/951021/what-is-the-javas...

the async way doesn't seem to work inside the walk function, but the older (and uglier imo) way does

As an example here is the modified code for https://turtletoy.net/turtle/eed0f57234

  // You can find the Turtle API reference here: https://turtletoy.net/syntax
  Canvas.setpenopacity(1);
  
  // Global code will be evaluated once.
  const turtle = new Turtle();
  turtle.penup();
  turtle.goto(0,0);
  turtle.pendown();
  
  function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }
  function pausecomp(millis)
  {
      var date = new Date();
      var curDate = null;
      do { curDate = new Date(); }
      while(curDate-date < millis);
  }
  // The walk function will be called until it returns false.
  function walk(i) {
      turtle.forward(i);
      turtle.right(150);
      //await sleep(100); //await not valid inside the walk function
      pausecomp(50)
      return i < 200;
  }
edit: implemented: https://turtletoy.net/turtle/e99ca811ad


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: