|
pepito sanchez posted:It just never goes back into the function. I've tried using a simple if statement, and a while wouldn't work because that would create an infinite loop which locks the script up. It goes through the function once, stores nothing, returns nothing, and compares nothing. I can see how the logic is wrong, yet I don't know how to make it so it constantly searches for player1's input. There seems to be a fundamental misunderstanding here: Do not run the .on() function more than once per element. The .on() function adds an event handler for the named event. Every time you run .on('click', function ...), you are saying "when the user clicks this element, also run this function in addition to other functions that already run." I have rewritten your code above so that it works exactly as it did before, but hopefully the logic is clearer: JavaScript code:
JavaScript code:
|
# ? Jun 9, 2014 06:33 |
|
|
# ? May 29, 2024 03:18 |
|
Plorkyeran posted:Did you actually read that article, or did you just laugh at the introduction then close the page? It doesn't actually try to claim that AppCache is unusable; merely that it has a bunch of gotchas you have to keep in mind. God bless anyone who could make it through that whole thing, that was terribly written.
|
# ? Jun 9, 2014 12:32 |
|
Tres Burritos posted:God bless anyone who could make it through that whole thing, that was terribly written. Thank god someone else thinks that. I hated that article and I find it obnoxious not only in its writing style, but also how its turned people off AppCache just due to how negative the article reads, disregarding the facts presented. Its not technical, but its not a manifesto either, It just sort of.. is.
|
# ? Jun 9, 2014 16:12 |
|
Thanks, Wheany. I also learned today that writing var storedSequence = gameMode.sequence only created a reference to the gameMode.sequence array. It didn't actually copy its contents into a new variable. I have to clone it, or slice it. I also have to rewrite lots of code so everything is stored in a single associative array instead of two separate player arrays. It should simplify things in the long run. edit: Yet I'm having serious issues with that. It's a lot to check for and I don't know how, even after searching through articles about JS associative arrays. For example, how would I check if a player already exists in the array? And how would I capture that position in the array to, say, update existing "point" value. It's an issue because the array is constantly growing, it's never going to be player1 and player2 again and again. I was thinking perhaps add two seperate arrays to an associative array at the end of the game? I did post on stackoverflow for help: http://stackoverflow.com/questions/24124769/jquery-and-javascript-to-keep-track-of-two-players-in-one-associative-array <e/n>Honestly this whole project is kind of lame. He's teaching us as we're supposed to be working on it. I've rewritten so much code it's as if I never make progress. </e/n> pepito sanchez fucked around with this message at 18:12 on Jun 9, 2014 |
# ? Jun 9, 2014 17:01 |
|
Plorkyeran posted:Did you actually read that article, or did you just laugh at the introduction then close the page? It doesn't actually try to claim that AppCache is unusable; merely that it has a bunch of gotchas you have to keep in mind. Yeah man, anything with douchebag in the title is great on that alone. Albeit this article was written ~2 years ago, and I'm guessing poo poo has changed, there's just way too many conditions you have to work around to make it work. The only reason to use it is you literally have no other option if what you want to do is get your website working offline at the time. I skimmed the article, but also read that he suggests its best for SPAs, but not for normal websites which was my viewpoint around that time. Anyways maybe my original statement was too harsh, but it's definitely not the solution to storing files without a server. Have not tried the iframe trick or whatever so could be wrong.
|
# ? Jun 9, 2014 18:23 |
|
pepito sanchez posted:edit: Yet I'm having serious issues with that. It's a lot to check for and I don't know how, even after searching through articles about JS associative arrays. For example, how would I check if a player already exists in the array? And how would I capture that position in the array to, say, update existing "point" value. It's an issue because the array is constantly growing, it's never going to be player1 and player2 again and again. I was thinking perhaps add two seperate arrays to an associative array at the end of the game? What do you mean by associative array? That is a PHP term. Do you mean a "plain" object, or an array (which is possible, but can be confusing, since arrays are also objects, just a special case). Also the syntax can look like array access: someObject['someProperty'] = "a value"; If you have an array, you can use the indexOf function of the array to search for your value. If you have a non-array object, you have to iterate through the properties and compare the values. You can use jQuery's $.each() for that. You can actually user $.each() for both cases, but you don't need to use it with an array. But I don't really see why you would need to store your player objects in an array, if there are always just two players.
|
# ? Jun 9, 2014 19:44 |
|
Err just translating from spanish there. "Array asociativo," yeah it's just storing arrays inside an array. It's never just between two players. An existing player can use his name again, for example, and at the end of the game his existing score would be updated. That's why I need every player to be part of one array, to search all names through one array, etc. Otherwise, player1 could simply use the same name in player2's submit field, and the game would have no way of knowing that player's name already exists in player1's array. edit: The end of both game and project is making an updated list of players based on their points, so it's just ideal to have everything as part of one array. This list has an indefinite amount of players. Stackoverflow suggests the .grep JQuery function, which I had no idea existed. Trying to wrap my head around it now. pepito sanchez fucked around with this message at 02:30 on Jun 10, 2014 |
# ? Jun 10, 2014 02:27 |
|
So I'm making a javascript based game and I want to use key combinations ctrl-1, ctrl-2, etc. This appears to work fine in chrome on a mac, but the windows chrome apparently uses these to select between tabs. Is there anyway to prevent that?
|
# ? Jun 10, 2014 21:36 |
HappyHippo posted:So I'm making a javascript based game and I want to use key combinations ctrl-1, ctrl-2, etc. This appears to work fine in chrome on a mac, but the windows chrome apparently uses these to select between tabs. Is there anyway to prevent that? Tried using http://api.jquery.com/event.preventdefault/
|
|
# ? Jun 10, 2014 21:40 |
|
HappyHippo posted:So I'm making a javascript based game and I want to use key combinations ctrl-1, ctrl-2, etc. This appears to work fine in chrome on a mac, but the windows chrome apparently uses these to select between tabs. Is there anyway to prevent that? How are you capturing it? You should get first crack at it in keydown, with evt.ctrlKey set. You also need to cancel the default processing of the event; returning false from your keydown handler works.
|
# ? Jun 10, 2014 21:51 |
|
Subjunctive posted:How are you capturing it? You should get first crack at it in keydown, with evt.ctrlKey set. This did it, thanks
|
# ? Jun 10, 2014 22:23 |
|
Major noob here. I'm sure that I'm making many mistakes but this one has me pretty confused. I've got most of the behavior of this page functioning as I think it should but two of the monster "types", those being electric and fire are not showing the nextLevel value. I don't really understand why not? http://jsfiddle.net/orenthal/3HsSs/
|
# ? Jun 11, 2014 08:09 |
|
Citizen Jerk posted:Major noob here. I'm sure that I'm making many mistakes but this one has me pretty confused. Those two monster types progress bars are too narrow, because their baseXP is lower. The "100" gets pushed to the next row (and thus hidden).
|
# ? Jun 11, 2014 08:40 |
|
I didn't even consider the width of the active area of the progress bar as I was ignorantly looking at the bar as a whole. Thanks a million.
|
# ? Jun 11, 2014 08:43 |
|
So everything was going great. Simon was working, my sequences were showing, and players were playing. Would you believe I never actually played Simon? I was delivering the full sequence to both players before it's their turn, and that's just not how the game is played. I've had to recode a bunch of stuff so that the sequences are shown a little bit at a time. With each "round," the players each go into their turn. That's not so much of a problem. My problem is simply showing the sequences a bit at a time. I was using a for loop, until I remembered for doesn't really work. Now I'm stuck... again. I'm trying to replace it using $.each, and I've read up on the JQuery API for it, but I'm still not sure how to implement it in this function. code:
|
# ? Jun 13, 2014 15:05 |
|
I'm dicking around with WebGL and thanks to some OpenGL experience with C++ I figured most stuff out, but ran into an issue with textures that seems pretty simple. Basically, I can't get multiple textures (one for each of a handful of objects, not bumpmaps or anything) to work - one is ok, but the moment I try to stick it into an array, everything stops working:JavaScript code:
mobby_6kl fucked around with this message at 17:40 on Jun 13, 2014 |
# ? Jun 13, 2014 16:15 |
|
You're assigning to textures[i] rather than textures[i].texture. Also, use {}, not new Object().
|
# ? Jun 13, 2014 16:30 |
|
Oops, that was a copy-paste error as I was trying out different things. Updated to what I actually have now (also including your {} suggestion). Same result, the alert gets fired anyway.
|
# ? Jun 13, 2014 17:38 |
|
mobby_6kl posted:Oops, that was a copy-paste error as I was trying out different things. Updated to what I actually have now (also including your {} suggestion). Same result, the alert gets fired anyway. You don't give enough context. Show the "simple variable" version, what does setup_texture do? Also, you immediately overwrite the empty object in textures[i] with gl.createTexture();
|
# ? Jun 13, 2014 18:22 |
|
pepito sanchez posted:
Well, I don't know how Simon is played either, but I'm going to help you with the for loop: JavaScript code:
|
# ? Jun 13, 2014 18:46 |
|
Wheany posted:You don't give enough context. Show the "simple variable" version, what does setup_texture do? Sure, this thing here works when placed instead of the previous code : JavaScript code:
JavaScript code:
|
# ? Jun 13, 2014 19:05 |
|
Okay, the problem is probably using setup_texture(textures[i]). The i variable is 5 at the end of that loop and textures[5] presumably is undefined. edit: Also gl.isTexture(textures[i]) is always false because the texture is setup asynchronously and it has not finished when you get to that point in the loop. (I assume) Wheany fucked around with this message at 19:46 on Jun 13, 2014 |
# ? Jun 13, 2014 19:44 |
|
edit: Wheany, your function shows every button at once. At least it's showing something again! The delay timer gets completely ignored, just like in a for loop, and it's not showing only the first button before moving on, which would be what I was trying to change in the first place. pepito sanchez fucked around with this message at 04:45 on Jun 14, 2014 |
# ? Jun 14, 2014 03:51 |
|
pepito sanchez posted:edit: Well if entryDisplayer works right with a single entry, maybe you can still use that to display a single entry. The delay timer is not ignored (I assume you mean setTimeout), that function just returns immediately, because it is asynchronous. Asynchronicity is the nature of javascript. You call a function that returns immediately, but you give that function a callback as a parameter. Once the function finishes doing what it is doing (For example: Once it is done waiting for 1 second), it calls the callback. Here is that piece of code from my last post edited again to assign one more function into variables: JavaScript code:
One common example is ajax calls, where you setup the connection and then have it connect. After the server returns a result (which can take a long time), your callback gets called with the result and you can process it.
|
# ? Jun 14, 2014 07:27 |
|
The problem is it reacts just like a for loop, so everything in the sequence shows at once. I got it to do what I wanted using a while inside an if.code:
code:
|
# ? Jun 15, 2014 17:05 |
|
pepito sanchez posted:The problem is it reacts just like a for loop, so everything in the sequence shows at once. I got it to do what I wanted using a while inside an if. I would change that playButtonSequence so that it simply shift()s one entry from the sequence, then feeds that entry to entryDisplayer. You probably have some timeout somewhere that calls playButtonSequence. But if it works, it works. pepito sanchez posted:Now the problem is when it gets into player1Turn() I make it push() numbers into player1's array, and mean it to go into player2Turn() once that array reaches sequenceCounter (so we know his turn is complete), yet it never compares it. It just stays stuck in player1Turn. Do you see it?
|
# ? Jun 15, 2014 22:52 |
|
No, I don't. Each click action is supposed to set it to false, but the && is what's important, if the player1.sequence meets sequenceCounter. Then it should ALL be true, and move onto player2Turn() Am I missing something obvious?
|
# ? Jun 15, 2014 23:19 |
|
pepito sanchez posted:No, I don't. Each click action is supposed to set it to false, but the && is what's important, if the player1.sequence meets sequenceCounter. Then it should ALL be true, and move onto player2Turn() code:
|
# ? Jun 16, 2014 00:18 |
|
Fish Ladder Theory posted:
And even it it wasn't, the logical and would still evaluate to false as a whole and the code inside the if block would be skipped.
|
# ? Jun 16, 2014 06:14 |
|
On my way... Why does the NetBeans IDE turn "sequence" into a dark color instead of its normal green when I do this? It's scaring me. code:
It it actually turning it into an integer?
|
# ? Jun 19, 2014 14:00 |
|
pepito sanchez posted:Why does the NetBeans IDE turn "sequence" into a dark color instead of its normal green when I do this? It's scaring me. That is entirely dependent on your IDE's syntax highlight settings, and not really related to JavaScript. It could be that it doesn't know what player1.sequence is, it could be warning you that player1.sequence might not have been initialized, or it could be something completely different.
|
# ? Jun 19, 2014 19:28 |
|
Is there a way to make Javascript pause and wait for input, in a fashion that doesn't use alert() or confirm()? I have code that runs through a set of instructions, but one of those instructions involves "waiting for user input and accepting a key press". My initial implementation was to start an infinite (or not infinite) while loop that would run as long as a certain variable was set to false. I was figuring that on a keydown event, that variable would be set to true, at which point that while loop would break and the code could continue. I tried implementing this, but it just hangs and never responds to anything I do Is there something particular about Javascript making something like this difficult?
|
# ? Jun 20, 2014 14:37 |
|
yes; javascript is single-threaded and can't block. you need to instead use a callback when the user input event occurs. you can call setTimeout() to invoke some piece of code after a delay, and then repeat until there's input, but this would be pretty inconvenient compared to an onTextChanged event or whatever
|
# ? Jun 20, 2014 14:55 |
|
Maybe this library would make things simpler? http://craig.is/killing/mice
|
# ? Jun 20, 2014 15:10 |
|
Pollyanna posted:Is there a way to make Javascript pause and wait for input, in a fashion that doesn't use alert() or confirm()? User input is async, right? So anything that depends on user input has to happen in a callback invoked after that input has been received. Here's a basic callback example. http://jsfiddle.net/LKs23/2 You could also look at promises using jQuery or Q if the behavior needs to be complex. Fish Ladder Theory fucked around with this message at 19:41 on Jun 20, 2014 |
# ? Jun 20, 2014 19:26 |
|
Wheany posted:Okay, the problem is probably using setup_texture(textures[i]). The i variable is 5 at the end of that loop and textures[5] presumably is undefined. Thanks! I'm probably mildly retarded because I never figured out where exactly the issue was, but I had to refactor everything anyway so I got rid of this thing altogether. Also totally right about isTexture, I realized that when I unrolled the loop and saw what was actually happening. I suppose I could ask this in the web design or 3d graphics threads, but what's generally the best way to overlay some 2d graphics over a WebGL scene? I'd need to have some responsive diagnostics and a basic UI that I'd prefer to draw myself.
|
# ? Jun 20, 2014 23:12 |
|
mobby_6kl posted:I suppose I could ask this in the web design or 3d graphics threads, but what's generally the best way to overlay some 2d graphics over a WebGL scene? I'd need to have some responsive diagnostics and a basic UI that I'd prefer to draw myself. Simplest is probably to position a <div> or 2D <canvas> over top of the WebGL scene's <canvas>. You can also use a 2D <canvas> as a texture if you want more control. Here's a simple example.
|
# ? Jun 21, 2014 00:31 |
|
I am using the InfoBox plugin to create custom interactive info-windows in google maps. From these infowindows users can scroll through a list and click on an image to invoke some script. Everything works, the issue is when enableEventPropagation is enabled I can click through the infobox to other markers which causes another infobox to pop up. When it is set to false I cannot use actions within the infobox(scroll, click) does anyone have experience solving this problem? code:
code:
code:
|
# ? Jun 26, 2014 14:06 |
|
I wrote a simple form input that does some calculations. Since I'm not writing to a database, do I need to sanitize my inputs? Basically the page takes in two integers, divides them and returns the value.
|
# ? Jun 29, 2014 01:26 |
|
|
# ? May 29, 2024 03:18 |
|
I'm messing around with AngularJS. I like it a lot so far, but I'm having a hard time figuring out how to make some pagination links. I haven't been able to find any good examples on stackoverflow etc My json schema already has pagination, it includes these items: code:
|
# ? Jun 29, 2014 02:44 |