Last active
          October 15, 2015 15:07 
        
      - 
      
- 
        Save indefinit/055cf41664fe8325eeed to your computer and use it in GitHub Desktop. 
    An example of using an object literal to schedule timing.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //define an object that holds lyrics and time codes | |
| //key = time in millis | |
| //val = "lyrics" | |
| var timecodes = { | |
| 100 : "One, two, three! My baby don't mess around Because she loves me so This I know fo sho!", | |
| 5000 : "But does she really wanna But can't stand to see me walk out the door Don't try to fight the feeling Because the thought alone is killin' me right now Thank God for Mom and Dad For sticking to together Like we don't know how" | |
| }; | |
| //function to process and schedule lyrics. | |
| //we pass an object as parameter to this function | |
| //only run this function once (if in p5js, do this in setup()) | |
| function processLyrics(lyricsObj){ | |
| //for each of the items in our lyrics object, loop | |
| for(var lyricTime in lyricsObj){ | |
| setTimeout(function(){ | |
| // do something with our lyrics string, | |
| // which can be accessed like this: lyricsObj[lyric] | |
| console.log(lyricsObj[lyric]); | |
| }, lyricTime); | |
| } | |
| } | |
| //if in p5js, run this function call inside setup() | |
| processLyrics(timecodes); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment