ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I don't know what library you're using, but it looks like it's being used as a callback: when PLAYER and ALIEN_BOMB collide (which uses the numbers 30 and 12 - perhaps defining the bound box around 'PLAYER'? You'd have to look up the docs for the function) run the function that.hit().
It's not a library, it's a paper book I'm reading.
Yes, I think you're right, but could you explain to me how "that.hit" WOULD be set up as a callback?
When a collision occurs, that routine would be invoked with some set of parameters so that you could remove the poor player, add an explosion, deduct lives or points. (Or maybe it's the other way around ... remove the poor alien bomb, add an explosion, add points. After all, it's your game.)
It's not a library, it's a paper book I'm reading.
Well... You're using a SYS_collisionManager class, which is either in a library or something you've defined but haven't told us about - all I was saying is that "I have no idea what that code is meant to do, but I'm making guesses based on what it looks like it should do".
Quote:
Originally Posted by resetreset
Yes, I think you're right, but could you explain to me how "that.hit" WOULD be set up as a callback?
You're essentially moving it into the scope of the function, as a variable. I haven't actually tested this code, so if it doesn't work tell me and I'll try to get it to do so, but the basic idea is:
Code:
function doSomething(callback){
callback("http://www.google.com");
}
doSomething(alert);
doSomething(function(s){ window.location.href = s; });
The first one calls 'alert' on the string "http://www.google.com" (displaying it in a popup) while the second runs an anonymous function (I can't remember if it's normal to call them lambda functions here) which sets window.localtion.href to "http://www.google.com" (redirecting the user to google).
EDIT: I stopped being lazy and checked that my code works, which it does. Any problems are therefore of your own devising :P
Sorry for the late reply, thanks a lot for your reply Snark, but I didn't get both lines of your code:
For "doSomething(alert);" , it means you're calling doSomething with an arg of alert, right? ie. it expects that there's a variable called alert, whose value will be passed to doSomething?
NOT the Javascript built-in FUNCTION alert, which will popup a window. So how does it work then?
And for "doSomething(function(s){ window.location.href = s; });" - well I just don't get it.
You're including the function's code as an arg to doSomething? How does that work?
By the way, could you recommend a good book on all this stuff? Is "Javascript: A Definitive Guide" a good one?
For "doSomething(alert);" , it means you're calling doSomething with an arg of alert, right? ie. it expects that there's a variable called alert, whose value will be passed to doSomething?
NOT the Javascript built-in FUNCTION alert, which will popup a window. So how does it work then?
You seem to have the idea that functions are different from values, but this is not the case. Other languages do make this distinction, but in JavaScript the story goes like this: there is a variable called alert whose value is a function that makes a popup window.
Quote:
And for "doSomething(function(s){ window.location.href = s; });" - well I just don't get it.
You're including the function's code as an arg to doSomething? How does that work?
Same here, a value (which happens to be a function) is being passed as an arg to doSomething.
Code:
// Instead of writing
function doSomething(callback) {...}
// you could say
doSomething = function(callback) {...}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.