Skip to reading
Replace the Built-in Screens

Personal notebook controller - part 1 of 3

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

Record ID: journal_tools. Global Script: on. Subscribe to OnPlayerChanged and OnSaveLoaded. All three parts belong to the same record.

Code example
extends "res://scripts/runtime/script_base.gd"
Code example
var previous: String = ""
Code example
func on_global_ready(_context: Dictionary = {}) -> void:
    set_process(true)
    render()
Code example
func on_player_changed(_context: Dictionary = {}) -> void:
    await SetVariable({"name":"journal_choice", "value":""})
    render()
Code example
func on_save_loaded(_context: Dictionary = {}) -> void:
    render()
Code example
func _process(_delta: float) -> void:
    var values: Dictionary = Runtime.get("variables")
    var current: String = ActivePlayer() + "|" + str(values.get("journal_choice", ""))
    if current != previous:
        render()

The player-change hook clears the old selected entry ID. The save-loaded hook redraws the reader from restored data. The small frame check notices the player selecting another title.

The event names in the subscription controls correspond to the on_player_changed and on_save_loaded functions. Defining those functions without the subscriptions is incomplete setup.

Page 78 of 88Permalink
Go to page