Help on Karel the Robot
Help on Karel the Robot
Layout of desktop
The desktop is divided into three panes: menu in the upper pane, yard in the left pane and help in the right pane, or something else. In the left pane, you can see Karel in his yard and current state beneath the yard. The state is usually "OK", or "yes" or "no" after having done some words. Additionally, information of the depth of nesting and of the number of loop passes is displayed while Karel is running.
In the right pane, you can see either help, dictionary or program listing, as appropriate. The right pane is used also for import and export of the dictionary.
Main menu, export, import
The main menu contains the following controls:
The dictionary button displays contents of dictionary into the right pane and adds the dictionary menu to the upper pane.
Use the import button to read the contents of dictionary from the file, where it has been exported earlier. Click the "import" button in menu and follow the instructions appearing in the right pane. Then click the "import" button at the bottom of the right pane, the contents of the right pane stores into the dictionary, to the yard, and Karel gets the appropriate position and orientation according to the contetnts of the text area. You can try to import contents of dictionary using the "examples.txt" file.
The export button writes the contents of the dictionary, the contents of the yard, Karels position and Karels orientation into an auxiliary window in the format that can be saved in a file. Follow instruction in the header in the right pane to save the contents of the right pane to the file (see also these remarks).
The help button displays this help document in special window.
Select with the what shall the mouse do in the yard? radio button, what effect you wish to have clicking into the yard: setting wall, putting a mark, lifting a mark, or moving Karel.
Note:
In addition to the option of exporting and importing the dictionary, the current state of the dictionary can be occasionally saved to the local storage, and the last saved state can then be restored when Karel is started. After changing the dictionary for the first time, you will be asked if you want to save the current state of the dictionary. If so, the dictionary is saved in the local storage in the item "KarelDictionary". In this way, it is possible to promptly resume work that has been interrupted. ATTENTION: The content of the storage is available only on the computer where it was saved and for the logged-in user who saved the content. Do export and import in order to transfer the contents of the dictionary to another computer or to another user.
Dictionary
The dictionary appears in the right pane. Click in the dictionary on the word you wish to select. Choose an activity in the dictionary menu (upper pane), which activity should be performed with the selected word. The dictionary menu contains the following controls:
The insert button opens a dialog box, where you write name of a new word, and then inserts the new word into the dictionary.
The erase button removes the actually selected word from the dictionary.
The rename button opens a dialog box, where you write a new name, and then renames the actually selected word in the dictionary.
The edit button displays in the right pane the pogram listing of the word, that is actually selected in the dictionary. The edit word menu gets displayed.
The run button launches a quick run of the actually selected word.
The word by word button launches a stepwise run of the actually selected word.
The animation button launches a slow run of the actually selected word. Control animation speed by a number in the text field.
The animation speed text field may be set to values in range from 1 to 9 (9 means the quickest animation).
Use the step inside / over radio button to select at the stewise running, whether all the nested words are to run statement-by-statement or just the word, you have actually selected in the dictionary. The nested words are the words, that are called from the word you have actually selected in the dictionary, or the words, that are called from the nested words.
Word Editing
In the right pane, you can see program listing of the word that is actually selected in the dictionary. You can see a link append beneath the listing. Clicking on that link appends a new statement to the end of the program of the word and starts to edit the new statement. If the word is empty, start to create the program just by clicking on the link.
A radio buttons with the following options appear in the menu:
Select edit and click on the desired statement in the listing to start editing the statement.
Select insert before and click on the desired statement in the listing to insert a new statement and start to edit it.
Select insert after and click on the desired statement in the listing to insert a new statement and start to edit it.
Select erase and click on the desired statement in the listing to remove the statement from the program.
Quit word editing e.g. by clicking on the "dictionary" button.
Statement Editing
Program listing of the word appears in the right pane. Menu consisting of at least the following controls appears in the upper pane:
Choicebox that lets you select a statement. Click on 🔽 to drop the list down.
The OK button finishes statement editing and resumes word editing.
The help button displays this help document in special window.
The if, while, repeat...times and repeat...until statements may contain some more controls.
If Statement Editing
Program listing of the word appears in the right pane. The following controls may appear in the menu in the upper pane:
Choicebox that lets you select a statement.
Choicebox that lets you invert the following condition.
Choicebox that lets you select a condition.
The insert inside button inserts a statement into the body of the if-statement (into the "then" branch).
The insert "else" button inserts a statement into the if-statement in the "else" branch.
The OK button finishes statement editing and resumes word editing.
The help button displays this help document in special window.
While Statement Editing
Program listing of the word appears in the right pane. The following controls may appear in the menu in the upper pane:
Choicebox that lets you select a statement.
Choicebox that lets you invert the following condition.
Choicebox that lets you select a condition.
The insert inside button inserts a statement into the body of the while-statement.
The OK button finishes statement editing and resumes word editing.
The help button displays this help document in special window.
Repeat ... Times Statement Editing
Program listing of the word appears in the right pane. The following controls may appear in the menu in the upper pane:
Choicebox that lets you select a statement.
Text field, where you can write the desired number of repetitions (an integer).
Choicebox that lets you select a variant of a repeat-statement: the "repeat ... until" statement finishes as the condition is satisfied, the "repeat ... times" statement performs the specified number of repetitions.
The insert inside button inserts a statement into the body of the repeat-statement.
The OK button finishes statement editing and resumes word editing.
The help button displays this help document in special window.
Repeat ... Until Statement Editing
Program listing of the word appears in the right pane. The following controls may appear in the menu in the upper pane:
Choicebox that lets you select a statement.
Choicebox that lets you select a variant of a repeat-statement: the "repeat ... until" statement finishes as the condition is satisfied, the "repeat ... times" statement performs the specified number of repetitions.
Choicebox that lets you invert the following condition.
Choicebox that lets you select a condition.
The insert inside button inserts a statement into the body of the repeat-statement.
The OK button finishes statement editing and resumes word editing.
The help button displays this help document in special window.
Running, Word by Word, Animation
Quick running is as quick as possible and displays only a result. Word-by-word running or animation allows you to observe Karels behavior in the yard, actual status and the statements actually being performed. The following controls may appear in the menu:
The go on button performs single step in the program of the word.
The stop button stops Karel and displays a message. Click that button when Karel runs too long – the words program probably contains an endless loop or too deep recursion. If recursion depth exceeds a preset limit, Karel stops itself and displays a message. If a loop exceeds a preset limit of repetitions, Karel also stops itself and displays a message.
The help button displays this help document in special window.
Constants Settings
You may set the following constants just in javascript in the "karel.htm" file:
dimension = 8; ...size of the Karels yard
ms_thisfilename = "karel.htm"; ...name of the file that contains Karel
machine__max_nest = 1000; ...limit depth of recursion
machine__max_loops = 200; ...max. nr. of repetitions in "while" or "until" loops
mi_speed = 5; ...default speed of animation (appears in menu)
ms_importfile = spell["priklady"]; ...default filename to be imported (appears in menu)
As the limit depth of recursion is reached, a message is displayed and Karel stops. Additionally to word calls, also nesting of structured statements "if", "while" and "repeat" is included into the depth of recursion.
Localization
Karel is available now in English and Czech. Every localization has its spelling vocabulary in the "spell_en.js" or "spell_cz.js" file. Do you wish to change the language, create a copy of the appropriate spelling vocabulary and name it "spell.js".
If you wish to create another localization, create a new spelling vocabulary file and a new help file. The spelling vocabulary consists of assignments, text in the desired language is at the right to the equal sign. The "karhelp" item contains name of the helpfile, e.g.:
spell ["karhelp"] = "khelp_en.htm";
Copyright
Karel has been written in javascript by me, (c) Ivan Ryant 2000-2001. I provide it freely for nonprofit use and distribution. Other eventual ways of usage or distribution requires special agreement.
The program is provided as is. The program may contain unintentional faults, thats why I give no guarantees and reject any responsibility for damages that may arise by usage of the program. Tell me please eventual comments or messages of failures preferably by e-mail.
Notes on Version
I wrote this implementation of Karel mainly to learn javascript. That's why I made it a bit dirty and buggy and why the bugs are hard to fix and correct. That was in August 2000–January 2001.
I tried to adapt Karel to Netscape in July–August 2001. I had to completely rewrite menu, because I was not able to set the DISPLAY=none attribute in the DIV element. Thus buttons in the menu could not be just hidden and shown, but the whole frame of menu has to be replaced with new document on every click. Unfortunately, document replacing must not be launched by a button, that is part of the document being replaced, thus I changed all buttons to hyperlinks. Choiceboxes cannot by implemented as SELECT elements for the same reason, therefore I changed them all to hyperlinks, too, and I display the list of options in the frame, where the yard normally appears. Occasionally, I also changed the radiobuttons to hyperlinks. I achieved, the English version goes somewhat, but the Czech version still makes troubles (not only displaying is the issue, but processing in javascript including storing the dictionary in javascript objects, as well).
All the new discovered bugs have been fixed in October-November 2002 and user interface has been improved. I corrected deletion and renaming words in dictionary and the bug in program editing (the second and all the following statements were deleted instead of the first statement in a word). Result of a condition appears now below the yard modified with is/isnt in the if, while and repeat...until statements (e.g. Karel stands at a wall and the if isn't wall command is performed: NO appears now instead of original YES; in the case of the if is wall command YES appears now like originally). The dictionary is exported now into special window, not in the right pane any more - Save as menu command may be used in NS. After import, contents of the dictionary appears in the right pane automatically. Limit on loop repetition has been imposed, thus loops cannot repeat forever (only depth of recursion has been limited originally). Arrays in javascript are indexed now with text strings, that contain merely ASCII characters (simply said, I code strings hexadecimally, but originally, I indexed arrays directly with words from dictionary - I hope, difficulties with Czech language disappear this way).
In autumn 2023, I have ported this implementation of "Karel the Robot" to current versions of Mozilla Firefox 120.0 for Linux Mint (64 bits) and Chromium version 116.0.5845.102 (official build for Debian).
Known Bugs
Using ctrl-R, Karel reloads incorrectly. The same error also occurs when clicking on the corresponding icon in the header of the web browser. Instead, place the cursor in the address bar (e.g. by clicking the mouse) and press Enter to reload the entire page with Karel.
I fixed the other bugs being known up to the December 8, 2023.
In autumn 2023, I have ported "Karel the Robot" to current web browsers. I originally wrote the implementation of Karel for web browsers in 2001 for MSIE5. In 2002, I modified Karel under MSIE6. I tried to adapt Karel also under Netscape Communicator 4.78, unfortunately not with complete success:
I am not sure, whether the Czech version which uses codepage windows-1250 or iso-8859-2 works correctly. Don't forget adding Czech into the list of languages in Edit/Preferences/Navigator/Languages.
The user is erroneously allowed to change the contents of export and import, because the DISABLED attribute in the TEXTAREA element is ignored.
The instruction, that is displayed on export, is not correct. The source code is not displayed in notepad and cannot be saved. You can run notepad, of course, on Your own and move the source code there through clipboard. In NS, even the menu command File/Save As... works correctly but MSIE saves incorrect contents!
All hyperlinks are underlined, because the A {text-decoration=none} style is ignored.
I don't know whether Karel works well under other browsers. Fundamental condition must be satisfied that browser supports javascript and that scripts are permitted. In MSIE set option Tools/Internet Options/Security/Own level/Scripting: enable. Troubles can be met if documents are displayed from cache instead of documents fresh generated. My selection in MSIE is Tools/Internet Options/Common/Settings/Check for new versions of cached pages: Automatically. Using "back" button may prove harmless, but it can even surprise you. Troubles with Czech language can be sometimes solved by selecting the Czech codepage (e.g. windows-1250) as a default (e.g. in NS Navigator select View/Character Set/Set Default Character Set). Learn version of the currently running browser here.
Tell me please comments or messages of failures preferably by e-mail.