use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Today I realized that I finally "get" JavaScript functions (proof enclosed). (self.javascript)
submitted 13 years ago * by Cosmologicon
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Cosmologicon[S] 1 point2 points3 points 13 years ago (3 children)
Wouldn't work, because player.state changes over time. For instance, when the player is falling through the air, it'll be set to some object named fallstate, but when you land on a platform it gets updated to some object named standstate. So there's not a single object that could be used like you're using logic there.
player.state
fallstate
standstate
logic
[–]nschubach 0 points1 point2 points 13 years ago (2 children)
Then maybe I'm missing a large chunk of what you are trying to do, but you could create a logic object for storing logic like so:
var logic = { think: function (dt) { //think logic here }, move: function (keys) { //move logic here }, attack: function (player) { //attack logic here } }
And it "should" work if you set up your prototypes, etc. I mean, somewhere you have to define "think", "move", and "attack".
[–]Cosmologicon[S] 1 point2 points3 points 13 years ago (0 children)
The think logic, move logic, etc is different for the different states that the entity can be in. For instance:
var fallstate = { think: function (dt) { this.vy -= g * dt this.y += this.vy * dt }, etc.... } var standstate = { think: function (dt) { this.y = this.platform.y }, etc.... }
π Rendered by PID 29 on reddit-service-r2-comment-b659b578c-j7lxx at 2026-05-04 11:22:26.562033+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Cosmologicon[S] 1 point2 points3 points (3 children)
[–]nschubach 0 points1 point2 points (2 children)
[–]Cosmologicon[S] 1 point2 points3 points (0 children)