Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6226255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:59:28+00:00 2026-05-24T08:59:28+00:00

I have created a little robot like the Karel robot ( Wikipedia ) which

  • 0

I have created a little robot like the Karel robot (Wikipedia) which is based on javascript.

Karel4Web

The robot can be controlled with some simple commands such as “forward”, “turnright” and so on.

The user can write a javascript program to control the robot which then goes through javascripts “eval()” function so that the robot moves.

The problem is that I want the robot to move slowly so that you can see what he is doing and so that you can highlight the current code line in the editor.

Current method: Parsing

At the moment I have solved this (in the offline version) by parsing each line in the textarea and then building a stack of action which are then executed one after another with window.setTimeout. But this is of course limited because I have to write parsing code for every little javascript language contruct which is much work and error prone.

Some additional information to this:

Parsing version: http://abi-physik.de/_niki2/niki.php

Parsing version js code: http://abi-physik.de/_niki2/js/niki.js

Important functions are at the bottom of the script: run(), execute()

I am currently parsing the user script line by line and adding the actions to a stack. If the parser encounters an “if” it will begin a new stack and add all actions to that stack. if the parser then encounters an “}” it will close the “if” stack and continue to add actions to the base stack.

Any idea to improve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:59:29+00:00Added an answer on May 24, 2026 at 8:59 am

    I would say have those functions register to some queue instead of having them execute the JavaScript directly.

    var moveQueue = [];
    
    function forward(){
      moveQueue.push(_forward);
    }
    function _forward(){
        alert("move forward");
    }
    
    function backward(){
      moveQueue.push(_backward);
    }
    function _backward(){
        alert("move backward");
    }
    

    Than when it runs you would use a setTimeout and

    function run(){
        var curStep = 0;
       function go(){
          moveQueue[curStep]();
          curStep++;
          if(curStep<moveQueue.length){
              window.setTimeout(go,500);
          }
       }  
    }
    

    You still would need to parse it out to figure out the if statement logic, but this is one of many ways that will allow you to control the speed of execution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have created a little application to move some files around and put
I have a page which contains a jQuery-UI horizontal slider, created using a little
As you can see below I have created a little program to concatenate 2
I have created a little test project to try to resolve a problem I
I have created a little example,please have a look, http://jsfiddle.net/bWTwL/ I want to have
Ok, I have created a little utility with AppleScript and used Automator to turn
I am a little stuck. I have created almost everything in the picture below.
I'm a jQuery newbie, and I have trouble with a little script I created.
I have written a little console application that uses s#arp. I can create an
Little help need with jquery sortable. I have a nested list like so: <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.