Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Timeouts all the way down

Timeouts all the way down

Scheduled Pinned Locked Moved The Lounge
javascriptcssadobegame-devtools
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brady Kelly
    wrote on last edited by
    #1

    JavaScript timeouts, I mean. I'm trying my hand, for the first time ever, to do more than is necessary script. I'm developing a browser based flash-card game, and although I'm building up through independent functions, once I remove redundancy they all become temporally dependent, e.g. once started, the game uses timers to: - Pause before showing the first card in a round - Only show the card for a short time. - Hide the card and show the multiple choice answer card for a medium time - Repeat Each timer triggers the next, in simple code, so it looks like my final code will look like a spiral to hell with nested timeouts. Unless I Really put my mind to it - it could use a break from my perennial nemeses, the little layout/css snafus.

    "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

    L J Richard DeemingR 4 Replies Last reply
    0
    • B Brady Kelly

      JavaScript timeouts, I mean. I'm trying my hand, for the first time ever, to do more than is necessary script. I'm developing a browser based flash-card game, and although I'm building up through independent functions, once I remove redundancy they all become temporally dependent, e.g. once started, the game uses timers to: - Pause before showing the first card in a round - Only show the card for a short time. - Hide the card and show the multiple choice answer card for a medium time - Repeat Each timer triggers the next, in simple code, so it looks like my final code will look like a spiral to hell with nested timeouts. Unless I Really put my mind to it - it could use a break from my perennial nemeses, the little layout/css snafus.

      "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Brady Kelly wrote:

      Each timer triggers the next

      Found the bug. :-D Best Wishes, -David delaune

      J 1 Reply Last reply
      0
      • L Lost User

        Brady Kelly wrote:

        Each timer triggers the next

        Found the bug. :-D Best Wishes, -David delaune

        J Offline
        J Offline
        Jeremy Falcon
        wrote on last edited by
        #3

        :-D

        Jeremy Falcon

        1 Reply Last reply
        0
        • B Brady Kelly

          JavaScript timeouts, I mean. I'm trying my hand, for the first time ever, to do more than is necessary script. I'm developing a browser based flash-card game, and although I'm building up through independent functions, once I remove redundancy they all become temporally dependent, e.g. once started, the game uses timers to: - Pause before showing the first card in a round - Only show the card for a short time. - Hide the card and show the multiple choice answer card for a medium time - Repeat Each timer triggers the next, in simple code, so it looks like my final code will look like a spiral to hell with nested timeouts. Unless I Really put my mind to it - it could use a break from my perennial nemeses, the little layout/css snafus.

          "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

          J Offline
          J Offline
          Jeremy Falcon
          wrote on last edited by
          #4

          May wanna think about that design man. In years and years of JavaScript I've never had to nest or chain timers like that... ever. Promises or events yeah, but not timers.

          Jeremy Falcon

          1 Reply Last reply
          0
          • B Brady Kelly

            JavaScript timeouts, I mean. I'm trying my hand, for the first time ever, to do more than is necessary script. I'm developing a browser based flash-card game, and although I'm building up through independent functions, once I remove redundancy they all become temporally dependent, e.g. once started, the game uses timers to: - Pause before showing the first card in a round - Only show the card for a short time. - Hide the card and show the multiple choice answer card for a medium time - Repeat Each timer triggers the next, in simple code, so it looks like my final code will look like a spiral to hell with nested timeouts. Unless I Really put my mind to it - it could use a break from my perennial nemeses, the little layout/css snafus.

            "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Promises are the way to go. :) Something like this:

            // Starting a promise chain:
            function wait(timeout) {
            return new Promise(function(resolve) {
            setTimeout(resolve, timeout);
            });
            }

            // Continuing a promise chain
            function waitFor(timeout){
            return function(result){
            return new Promise(function(resolve){
            setTimeout(function(){ resolve(result); }, timeout);
            });
            };
            }

            Usage:

            wait(2000)
            .then(function() {
            alert("Thinking...");
            return 42;
            })
            .then(waitFor(1000))
            .then(function(result) {
            alert("The answer is " + result)
            });


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            J 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              Promises are the way to go. :) Something like this:

              // Starting a promise chain:
              function wait(timeout) {
              return new Promise(function(resolve) {
              setTimeout(resolve, timeout);
              });
              }

              // Continuing a promise chain
              function waitFor(timeout){
              return function(result){
              return new Promise(function(resolve){
              setTimeout(function(){ resolve(result); }, timeout);
              });
              };
              }

              Usage:

              wait(2000)
              .then(function() {
              alert("Thinking...");
              return 42;
              })
              .then(waitFor(1000))
              .then(function(result) {
              alert("The answer is " + result)
              });


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              J Offline
              J Offline
              Jeremy Falcon
              wrote on last edited by
              #6

              I'm the one that up-voted this, but I would like to add a suggestion. If his intent is to do simple animation with this, he's much better off using CSS3 animation with keyframes.

              Jeremy Falcon

              B 1 Reply Last reply
              0
              • B Brady Kelly

                JavaScript timeouts, I mean. I'm trying my hand, for the first time ever, to do more than is necessary script. I'm developing a browser based flash-card game, and although I'm building up through independent functions, once I remove redundancy they all become temporally dependent, e.g. once started, the game uses timers to: - Pause before showing the first card in a round - Only show the card for a short time. - Hide the card and show the multiple choice answer card for a medium time - Repeat Each timer triggers the next, in simple code, so it looks like my final code will look like a spiral to hell with nested timeouts. Unless I Really put my mind to it - it could use a break from my perennial nemeses, the little layout/css snafus.

                "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

                J Offline
                J Offline
                Jeremy Falcon
                wrote on last edited by
                #7

                Also, if your intent is simple animation, delay the showing of a card, etc. you can use CSS3 to pull that off with much less hassle.

                Jeremy Falcon

                B 1 Reply Last reply
                0
                • J Jeremy Falcon

                  Also, if your intent is simple animation, delay the showing of a card, etc. you can use CSS3 to pull that off with much less hassle.

                  Jeremy Falcon

                  B Offline
                  B Offline
                  Brady Kelly
                  wrote on last edited by
                  #8

                  Near top of the list for iteration 2.

                  "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

                  1 Reply Last reply
                  0
                  • J Jeremy Falcon

                    I'm the one that up-voted this, but I would like to add a suggestion. If his intent is to do simple animation with this, he's much better off using CSS3 animation with keyframes.

                    Jeremy Falcon

                    B Offline
                    B Offline
                    Brady Kelly
                    wrote on last edited by
                    #9

                    Thanks, Jeremy. I do plan to do basic animations, like a e.g. rapid fade-in of card as it is flashed on and fade-out when it gets "turned face down" again, but my main concern with timers is game logic. A visibly reducing wait until the next card is shown, then a very short wait while the card is shown, etc. Also the time the player has to choose an answer must be limited, quickest answers tracked, all that spade work.

                    "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

                    J 1 Reply Last reply
                    0
                    • B Brady Kelly

                      Thanks, Jeremy. I do plan to do basic animations, like a e.g. rapid fade-in of card as it is flashed on and fade-out when it gets "turned face down" again, but my main concern with timers is game logic. A visibly reducing wait until the next card is shown, then a very short wait while the card is shown, etc. Also the time the player has to choose an answer must be limited, quickest answers tracked, all that spade work.

                      "'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself." —Aleister Crowley

                      J Offline
                      J Offline
                      Jeremy Falcon
                      wrote on last edited by
                      #10

                      Sounds cool man. I hope it comes out awesome.

                      Jeremy Falcon

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups