Skip to reading
First Light, Part 4: The Message in the Machine

Keep time while the player can act

Edition 0.86.3.4

Part 4 of the First Light course. Build a two-character rescue using shared variables, attach-point alignment, sparks, a camera close-up, separate journals and a timed lift reserve.

Download PDFView illustrations

13 / SCRIPT 5 OF 5

1. Script ID: reserve_timer. Name it Reserve Timer. This time check Global Script › Keep global instance alive. Paste the code, validate, apply and save. It runs while either character is active. Leave it unattached to the room objects.

Code example
var fraction := 0.0
Code example
func _process(delta):
    if Runtime == null:
Code example
        return
Code example
    var left = int(Runtime.variables.get("lift_seconds", 0))
    if left <= 0:
Code example
        fraction = 0.0
        return
    if not Runtime.ready_for_input or Runtime.input_locked:
        return
    fraction += delta
Code example
    var whole := int(fraction)
    if whole > 0:
        fraction -= whole
        await SetVariable({"name": "lift_seconds", "value": maxi(0, left - whole)})

2. Understand the countdown. PCA calls _process each frame. delta is the sliver of time since the last frame. The script collects those slivers and removes whole seconds from lift_seconds. Otherwise a fast computer could empty the bar faster than a slow one.

While the runtime is preparing the next room or has locked player input, the count waits. The save slot holds the remaining whole seconds, so loading a slot resumes from that number. Reaching zero empties the reserve and leaves the repair in place.

[1] Validate the script. [2] Apply Changes, then Save Project in the main toolbar.

If the bar stays full, first check the global checkbox on Reserve Timer. If Pip’s cabinet says there’s no reserve while the bar still looks full, check the progress element’s variable binding on page 8.

Page 14 of 16Permalink
Go to page

Continue your 3D adventure

  1. Part 1First Light, Part 1: Your First 3D Adventure
  2. Part 2First Light, Part 2: Three Knocks
  3. Part 3First Light, Part 3: Behind the Wall
  4. Part 4First Light, Part 4: The Message in the Machine
  5. Part 5First Light, Part 5: The Clockmaker’s Secret
  6. Part 6First Light, Part 6: The Final Hour