Choice condition & label var

This commit is contained in:
2020-10-04 23:36:52 -06:00
parent 1a26240503
commit 756e316866
6 changed files with 35 additions and 8 deletions

View File

@@ -33,25 +33,34 @@ class Story {
this.storyScript = storyScript;
teller = storyTeller;
}
public function run() {
// TODO make a way to do all this loading before calling run(), but still make sure all the loading happens if it hasn't:
interp = new CCInterp();
reader = new HissReader(interp); // It references the same CCInterp but has its own readtable
interp.importFunction(storyTeller, storyTeller.handleOutput, "*handle-output*");
interp.importFunction(storyTeller, storyTeller.handleChoices, "*handle-choices*");
interp.importFunction(teller, teller.handleOutput, "*handle-output*");
interp.importFunction(teller, teller.handleChoices, "*handle-choices*");
interp.importFunction(this, hissRead, "hiss-read");
interp.importFunction(reader, reader.readDelimitedList, "hiss-read-delimited-list", List([Int(3)]) /* keep blankELements wrapped */, ["terminator", "delimiters", "start", "stream"]);
interp.importFunction(this, debugPrint, "print", T);
interp.load("hanklib.hiss");
}
public function run() {
interp.load("reader-macros.hiss");
var storyCode = interp.readAll(StaticFiles.getContent(storyScript));
// This has to happen AFTER reading the story, for (while) reasons
interp.truthy = (value) -> switch (value) {
case Nil: false;
case List([]): false;
case Int(0): false;
case String(""): false;
default: true;
};
if (debug) {
String("Main logic:").message();
storyCode.print();

View File

@@ -10,7 +10,7 @@ You have to make a choice.
* (label) A
-> start
+ {t} B
+ {(not label)} B
-> start
* C
-> end

View File

@@ -2,8 +2,8 @@ You have to make a choice.
* A
* B
* C
> 1
A
> 2
B
You have to make a choice.
* A
* B

View File

@@ -0,0 +1,11 @@
You have to make a choice.
* A
* B
* C
> 1
A
You have to make a choice.
* C
> 1
C
Good choice.

View File

@@ -71,5 +71,9 @@
(let (player-choice
(nth choices player-choice-index))
(choice-set-chosen-count! player-choice (+ 1 (choice-chosen-count player-choice)))
// increment the choice's label var
(when-let (label (choice-label player-choice))
(let (label-var (symbol label))
(eval `(defvar ,label-var (+ ,label-var 1)))))
(eval `(output t ,@(slice (choice-output player-choice) 2)))
(eval (choice-on-chosen player-choice))))))

View File

@@ -26,7 +26,9 @@
(read-all (first (HStream:take-until stream ["=="] nil nil t))))
// Define the knot's function at READ-TIME
// TODO define the knot's read count
(eval (print `(defun ,knot-name () ,@knot-body)))
// TODO increment the knot's read count in that function
nil))
(defun read-choice (start stream)
@@ -71,6 +73,7 @@
]
(+ delim " ")))
nil nil t))))) // don't drop the terminator
(when label (eval (print `(defvar ,(symbol label) 0)))) // start the label's variable at 0
(defchoice once-only depth label condition output 0 on-chosen)))