4
2
u/IronedSandwich May 07 '16 edited May 07 '16
+/u[EDIT: nope]/CompileBot javascript
function foo() {
console.log("FOO");
bar();
}
function bar() {
console.log("BAR);
foo();
}
foo()Hope I was fast enough
1
56
33
u/fukitol- Apr 12 '16
all it's missing is var isRunning = true; in the global scope, if(!isRunning) { return; } window.on('stopRunning', function() { isRunning = false; }); in bar() and processEvents(); in foo()
It's practically a game!
2
Apr 12 '16
Being serious: is it bad practice to have state variables in the global scope like that, in general?
3
u/fukitol- Apr 12 '16
Generally, with something like a game loop, there's going to be some sort of state being stored at the global scope. For instance, I might store the
playerthere. But most things should rely solely on events, and anything in the global scope should be kept to a minimum.4
u/the_omega99 Apr 12 '16
Eh? It doesn't have to be global. Assuming that only the loop needs to be aware that it's running, you can encapsulate it in something where it isn't accessible.
10
6
1
u/Zatherz May 12 '16
MC_Labs15
Hey, I used to watch your videos a long time ago.
1
u/MC_Labs15 May 12 '16
Hey! Yeah, I haven't actually made one in quite a while. I should start doing it again
5
u/Kilazur Apr 12 '16
What does this do in SHITTYprogramming? It's obviously to implement a double buffering later.
1
28
u/auxiliary-character Apr 12 '16
I forget, does javascript have tail call recursion?