Last active
August 29, 2015 13:57
-
-
Save Sanqui/9758146 to your computer and use it in GitHub Desktop.
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
| // how the hell do I do this | |
| function script() { | |
| this.turn_player() // instant action, so it's cool | |
| this.speak("Hello!") // blocking - must wait for user input | |
| answer = this.ask("Are you feeling well?") // uh oh... | |
| if (answer) { // runtime condition | |
| this.speak("That's nice!") //welp. | |
| } | |
| else { | |
| this.speak("Unfortunate. Have money.") | |
| this.give_gold(500) | |
| } | |
| } | |
| // when Javascript is fundamentally asynch. how do I do a game script. | |
| // no, the following are NOT good solutions: | |
| // callback hell | |
| function script() { | |
| this.turn_player(function(){ | |
| this.speak("Hello!", function() { | |
| this.ask("Are you feeling well?", function(answer) { | |
| if (answer) { | |
| this.speak("That's nice!") | |
| } | |
| else { | |
| this.speak("Unfortunate. Have money.", function() { | |
| this.give_gold(500) | |
| }) | |
| } | |
| }) | |
| }) | |
| }) | |
| } | |
| // token array | |
| script = [function(){this.turn_player()}, function(){this.speak("Hello")}, function(){this.ask("Are you feeling well?"}, function(){ if (answer) { this.speak("That's nice!") } else { this.speak("Unfortunate. Have money.", function(){ this.give_gold(500) })}}] | |
| // nor this nicer one. | |
| script = [this.turn_player, [this.speak, "Hello"], [this.ask, "Are you feeling well?", [[this.speak, "That's nice!"]], [[this.speak, "Unfortunate. Have money."], [this.give_gold, 500]]] | |
| // nor any kinda stupid custom script syntax. I want to write javascript dammit. | |
| script = 'turn_player \n\ | |
| speak "Hello!" \n\ | |
| ask "Are you feeling well?" \n\ | |
| yes: \n\ | |
| speak "That\'s nice!" \n\ | |
| no: \n\ | |
| speak "Unfortunate. Have money." \n\ | |
| give_gold 500' | |
| // yield attempt (am I doing it right?) | |
| function script(params) { | |
| yield this.turn_player() // instant action, so it's cool | |
| yield this.speak("Hello!") // blocking - must wait for user input | |
| yield this.ask("Are you feeling well?") // uh oh... | |
| if (params.answer) { // runtime condition | |
| yield this.speak("That's nice!") //welp. | |
| } | |
| else { | |
| yield this.speak("Unfortunate. Have money.") | |
| yield this.give_gold(500) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment