Re: Webster van Robot help
- From: David Mark <dmark.cinsoft@xxxxxxxxx>
- Date: Tue, 25 Dec 2007 20:57:28 -0800 (PST)
On Dec 25, 10:44 pm, Steve Howell <showel...@xxxxxxxxx> wrote:
On Dec 25, 5:00 pm, David Mark <dmark.cins...@xxxxxxxxx> wrote:
On Dec 25, 7:04 pm, Steve Howell <showel...@xxxxxxxxx> wrote:
Install Microsoft Script Debugger or Visual studio.
First, thanks for all your suggestions.
I will try the tools above soon, but right now I'm borrowing somebody
else's computer, so I'm reluctant to install software.
Are there any tricks for debugging IE as it comes shipped? I am
getting cryptic errors like this:
Line: 19
Char: 1
Error: Object expected
Is the line number relative to the <script> statement?
I don't think so. Regardless, IE is known to report the wrong line
number for inline scripts. It will make things easier to put the
script in another file.
background-color:#EEEEEE; color:inherit
Done, although I don't understand what I'm fixing here.
Always specify both colors. You don't know what a user might specify
in their style sheets. What if the color for the element is #EEEEEE?
By the same token, make sure that the element inherits a color defined
in your style sheet.
Tiny is relative. Pixels are not.
font-size: 80%
Fixed.
function showMsg(the_message) {
document.the_form.the_text.value += (the_message + "\n");
document.forms['the_form'].elements['the_test'].value += ...
Done.
function World() {
this.robot_x = 1;
this.robot_y = 1;
this.robot_dir = "E";
this.north_walls = [];
this.east_walls = [];
this.num_aves = 12
this.num_streets = 10
I would think some of these should be parameters.
Eventually. As you notice in your later comments, the World() class
for now is just a singleton. The only reason I make it a class for
now is simple encapsulation. I want some of the implementation
details of the World model hidden from the rest of my code.
IIRC, you didn't hide anything. You could just as well have used
object literal notation.
function _coords() {
return this.robot_x + "," + this.robot_y;
}
this._coords = _coords;
Why the leading underscore? What is that supposed to denote?
I was just using a naming convention to suggest that _coords was an
internal implementation detail, and that callers would not want to
call it. It turns out it was dead code anyway, so I removed it.
If it was meant to be internal, you should have made it a nested
function, rather than a property of the object. Then you wouldn't
have had to rely on suggestion.
Your semi-colon key seems to have broke at this point.
I've obviously been spoiled by Python, Ruby, Firefox JS, etc. I have
tried to sprinkle in semicolons to fix IE, but IE is still broken.
It isn't an issue specific to IE. It is just bad practice to rely on
automatic semi-colon insertion.
Use a switch statement.
Thanks, good suggestion. I have since used a switch statement in a
couple places, as well as associative arrays.
There is no such thing as associative arrays in JavaScript.
[snip]
I would prefer to use the DOM, but when I tried that at first, I was
running into issues. I may have been fighting some red herrings due
to CSS, though, so I will try soon to go back to a more DOM-oriented
style.
If you want to manipulate tables in IE, innerHTML is out.
<a href="#" onClick="move(); return false;">move</a>
<a href="#" onClick="turnleft(); return false;">turnleft</a>
<a href="#" onClick="turnright(); return false;">turnright</a>
<a href="#" onClick="build_wall_on_left(); return
false;">build_wall_on_left</a>
<a href="#" onClick="start_over(); return false;">start_over</a>
These links (should really be buttons) should be generated with
script. They aren't going to do anything useful without script.
I'm not sure what you mean by that. The links work exactly as I
expect. When I click move, the robot does in fact move.
Turn off scripting and they will do nothing. That is why they should
be generated by script.
Here's the latest version:
<html>
<style type="text/css">
table {border-collapse: collapse;}
table.wvr th {background-color: #EEEEEE; color: inherit;}
table.wvr td {background: #FFFF00}
table.wvr td, th {height: 40px; width: 40px; text-align: center}
.heading {background: #FF00FF}
.north {border-top: solid red;}
.east {border-right: solid red;}
.no_north {border-top: solid white;}
.no_east {border-right: solid white;}
.robot {background: #FF8888}
.beeper {background: #00FFFF}
.tiny {font-size: 70%}
</style>
<body onload="create_world()">
<script type="text/javascript">
/*
Webster van Robot.
(c) GNU General Public license
*/
function text_box() {
return document.forms['the_form'].elements['the_text'];
}
function showMsg(the_message) {
text_box().value += the_message + "\n";
}
function clearMsg() {
text_box().value = '';
}
You should really test the return value of text_box before trying to
set its value property. And why are you using a function to retrieve
this element each time? You should assign it to a variable at the
outset and then test it before calling these message functions.
function World() {
this.robot_x = 1;
this.robot_y = 1;
this.robot_dir = "E";
this.north_walls = [];
this.east_walls = [];
this.num_aves = 12;
this.num_streets = 10;
this.left = {
'N': 'W',
'W': 'S',
'S': 'E',
'E': 'N'};
I take it this is what you meant by "associative arrays." This is an
object literal.
[snip]
.
- Follow-Ups:
- Re: Webster van Robot help
- From: Steve Howell
- Re: Webster van Robot help
- References:
- Webster van Robot help
- From: Steve Howell
- Re: Webster van Robot help
- From: David Mark
- Re: Webster van Robot help
- From: Steve Howell
- Webster van Robot help
- Prev by Date: Re: Webster van Robot help
- Next by Date: Re: Webster van Robot help
- Previous by thread: Re: Webster van Robot help
- Next by thread: Re: Webster van Robot help
- Index(es):
Relevant Pages
|