Skip to reading
Text & Sierra-Style Adventures

A6. Controller source: lines 176-210

Edition 0.86.3.4

Build a complete text or graphical parser adventure with typed commands, inventory puzzles and press-to-walk controls.

Download PDFView PDF page

Transcript output, one-time scoring and object availability.

Code example
    busy = false
    if text_mode():
        focus_command()
Code example
func clean(raw: String) -> String:
    var value: String = raw.to_lower().strip_edges()
    for mark: String in [".", ",", "!", "?", ":", ";"]:
        value = value.replace(mark, " ")
    var words: PackedStringArray = []
    for word: String in value.split(" ", false):
        if word not in ["a", "an", "the", "please"]:
            words.append(word)
    return " ".join(words)
Code example
func append_line(text: String) -> void:
    var lines: Array = Runtime.variables.get("ta_lines", [])
    lines.append(text)
    while lines.size() > 100:
        lines.pop_front()
    Runtime.variables["ta_lines"] = lines
Code example
func reply(text: String) -> void:
    append_line(text)
    Runtime.variables["ta_reply"] = text
    if not text_mode():
        Runtime.show_gui("reply_card")
        pending_reply = true
Code example
func award(flag: String, points: int) -> void:
    if bool(Runtime.variables.get(flag, false)):
        return
    Runtime.variables[flag] = true
    Runtime.variables["ta_score"] = int(
        Runtime.variables.get("ta_score", 0)) + points

Continue directly with the next source block.

Page 59 of 68Permalink
Go to page