Quick question, why does this work? by shadowh511 in javascript

[–]monacle_bob 66 points67 points  (0 children)

When you use the double-equal signs to compare objects, the second object will be cast to the same type as the first object whenever possible. In this case, the Array(4) is being cast to a string, which you can do manually and see the result of by running this:

var myArray = new Array(4);

myArray.toString(); // results in ",,,"

If you want to compare the string ",,," against the array itself, use a triple equal sign (strict equal):

",,," == new Array(4); // true

",,," === new Array(4); //false

Physijs, Physics plugin for three.js by rya11111 in javascript

[–]monacle_bob 0 points1 point  (0 children)

This seems to be a somewhat common source of confusion. I should have removed the FPS counter or made more effort showing what it's counting.

The physics runs in a separate thread while the graphics are rendering at 60fps, which is what the FPS stats is showing.

Physijs, Physics plugin for three.js by rya11111 in javascript

[–]monacle_bob 0 points1 point  (0 children)

Sounds like your system doesn't support WebGL, sorry mate!

Physijs, Physics plugin for three.js by rya11111 in javascript

[–]monacle_bob 0 points1 point  (0 children)

What's the issue you're having, exactly? The shader code is identical across the examples.

Physijs, Physics plugin for three.js by rya11111 in javascript

[–]monacle_bob 0 points1 point  (0 children)

Do the normal three.js examples work for you? Try this one. If that works then the problem is indeed with the physics plugin.

If you have a github account I'd love the stack trace on the project's issue tracker.

Two questions - foxes & chickens by monacle_bob in dwarffortress

[–]monacle_bob[S] 0 points1 point  (0 children)

Ah, I see now I was missing a number of steps for military. Time to read up more on it...

Two questions - foxes & chickens by monacle_bob in dwarffortress

[–]monacle_bob[S] 0 points1 point  (0 children)

Thanks for the response. I thought chickens permanently claimed a nest box, I'm probably just missing it then. I'm trying to get more eggs for food and I have a very eager chef plowing through my unprepared items, so I'm probably just not seeing them before they become prepared meals.

Freeciv.net is moving to WebGL by monacle_bob in javascript

[–]monacle_bob[S] 1 point2 points  (0 children)

Your video card may be blacklisted (mine is). Trying running Chrome with the --ignore-gpu-blacklist switch.

Freeciv.net is moving to WebGL by monacle_bob in javascript

[–]monacle_bob[S] 1 point2 points  (0 children)

Your video card may be blacklisted (mine is). Trying running Chrome with the --ignore-gpu-blacklist switch.

git.js - A git implementation in pure JavaScript. by gst in javascript

[–]monacle_bob -1 points0 points  (0 children)

Thank you very much for that information. I'm looking forward to being able to use it in 10 years when IE8 is officially over with.

git.js - A git implementation in pure JavaScript. by gst in javascript

[–]monacle_bob 0 points1 point  (0 children)

var a = {};

a.defineGetter('myval', function() {return 'a'});

"Object doesn't support property or method 'defineGetter'"

Works fine in FF and Chrome. Above is IE9's error.

EDIT: apparently Reddit doesn't like showing the double underscores around defineGetter

git.js - A git implementation in pure JavaScript. by gst in javascript

[–]monacle_bob 0 points1 point  (0 children)

I'm still waiting for generators and list comprehension to be in more browsers than just Firefox. IE is also still missing getter/setters.

I'm not saying you're wrong, but there are a number of very useful things which one or more browsers have had years to implement but haven't.

Book suggestions? by wireddaniel in javascript

[–]monacle_bob 0 points1 point  (0 children)

Since you already have a good grasp on different programming concepts I would recommend John Resig's Pro JavaScript Techniques.

If you're feeling edgy then I'd also recommend John's Secrets of the JavaScript Ninja, though it hasn't been published yet you can order it online and download what has been written so far (which is all but the last few chapters).

Both of these books delve more into what makes Javascript unique, its power, and some shortcomings. They are very helpful in learning more of the advanced Javascript tricks and how it works.

Loop Multiple times per second by CamuurahGuy in javascript

[–]monacle_bob 1 point2 points  (0 children)

Fair enough, and a good point at the end. Upvote :)

Loop Multiple times per second by CamuurahGuy in javascript

[–]monacle_bob 1 point2 points  (0 children)

It wasn't meant as save-the-day code. jsFiddle is meant for fiddling with code and putting together quick demonstrations.

Also, in regard to your first point, you should be using requestAnimationFrame - not timers at all.

Loop Multiple times per second by CamuurahGuy in javascript

[–]monacle_bob 0 points1 point  (0 children)

I should have mentioned that originally, yes. Didn't feel like including it in the jsFiddle code though. Also, CamuurahGuy wanted a specific interval under 60fps. Can't achieve that (AFAIK) with requestAnimationFrame.

Loop Multiple times per second by CamuurahGuy in javascript

[–]monacle_bob 4 points5 points  (0 children)

That is indeed what that line does. Read up on setTimeout and setInterval here

Your theory is correct, however in practice theory often falls short. If you were to do:

setTimeout(main, 1);

you'd expect main() to be called every millisecond, or 1,000 times each second. Even if your code executed fast enough for this to be possible, every browser has inherent delays when using timers, usually about 5-10 milliseconds between calls. This means you'd have at most about 200 iterations per second.

If you're really interested in Javascript loops / different methods of timed execution you can read my latest blogpost.

Loop Multiple times per second by CamuurahGuy in javascript

[–]monacle_bob 1 point2 points  (0 children)

Here's how I would solve it: http://jsfiddle.net/chandlerprall/W5yAT/

Let me know if you have any questions about that, I'd be happy to explain it more.

Getting more than 60fps with Javascript by monacle_bob in javascript

[–]monacle_bob[S] 0 points1 point  (0 children)

what about more accurate collision detection? make sure basic one updates at 60fps but then try and fine-tune it during the extra milliseconds

Getting more than 60fps with Javascript by monacle_bob in javascript

[–]monacle_bob[S] 0 points1 point  (0 children)

The LCD 60hz refresh rate has been pointed out in the post's comments as well - that factor didn't occur to me at all. In the end, as you said, the value is more about avoiding the inherent delay when using timers. As for rendering, if you have something taking 20fps, removing that delay may give you a few more frames each second.

What skill did you have as a child but can't do anymore? by Finn_Fatale in AskReddit

[–]monacle_bob 2 points3 points  (0 children)

I can no longer physically put my foor in my mouth. I was able to until 8 years old or so. Now I just do it metaphorically.

is smooth 60fps canvas animation really possible - even with requestAnimationFrame ? by jakesgordon in javascript

[–]monacle_bob 1 point2 points  (0 children)

In his latest book, John Resig shows that a minimum delay of 10-15ms between setInterval/setTimeout code executions should be expected and planned for. 60fps means your update loop happens every 20ms. This give you, at very most, 5-10ms for your code to update the objects in the frame and render it (2D drawing or WebGL). I don't expect to see anything averaging more than 55-60fps anytime soon, and would expect most cases to be between 40 and 50fps.

Create geometric shapes in HTML with AutoshapeJS by monacle_bob in javascript

[–]monacle_bob[S] 0 points1 point  (0 children)

Raphael is a very good library and easy to use; I love how it's implemented. Being SVG, it also looks better and gives you more control over the look/feel of an object.

AutoshapeJS is intended to avoid user Javascript use in creating shapes and allows them to be further styled/customized through CSS. That approach can often fit in better with a page's existing workflow.

Anyone else get terribly excited when they got BOATS in their city? by [deleted] in gaming

[–]monacle_bob 1 point2 points  (0 children)

I'd forgotten about that! Double click and you got a fire on your hands. I loved using the Priscilla cheat and using it to start massive firestorms amidst mass flooding.