NRF SDK 0.9

Reading and acting

Test a mod with temporary overrides

Open a test session, observe decisions and release overrides explicitly.

A scenario tied to the mod contract

This path assumes a connected JVM application and a mod that accepts test operations. Start with game.mods.status(modId). Aspect codes and setting indices belong to the mod being tested: obtain them from its declarations rather than assigning universal meaning to an integer.

JVM function: acquisition, action and release through use
package wiki.controlrecipe

import fr.nimby.sdk.ControlResponse
import fr.nimby.sdk.Game
import fr.nimby.sdk.ModControlSession

fun <T> withSignalRecipe(
    game: Game,
    modId: String,
    signalId: Long,
    aspectFromMod: Int,
    observe: (ModControlSession, ControlResponse) -> T,
): T = game.mods.control(modId, leaseMillis = 5_000).use { recipe ->
    val accepted = recipe.forceSignal(signalId, aspectFromMod)
    observe(recipe, accepted)
}

The observe function supplied by your application schedules test readings during the lease. forceSignal accepts a request; its response alone does not prove that the mod’s next evaluation has already displayed that aspect. Use recipe.readSignal(signalId), then game observations, to check the expected outcome.

ReadingMeaning of active
readSignal0: no override; 1: override requested; 2: last observed decision matches the override.
readTrainA TrainControlState: Absent, AwaitingExit, Active, Completed or Cancelled. It does not grant movement permission.

constrainTrain expresses a speed in m/s, a mode and optionally an exit signal. releaseByRear selects release by the rear of the train; false uses the head. setSetting temporarily overrides a boolean setting; it does not write saved configuration. Counts describe requested overrides, not how many decisions have already executed.

Bound the duration and handle an uncertain response

  • A lease lasts 1,000 to 60,000 ms. There is no background renewal: renew is an explicit decision by the test.
  • restoreSignal, restoreTrain and restoreSetting release one target; clear releases the session’s overrides. close releases the lease and use calls close.
  • If the program disappears or cannot release its lease, expiration removes temporary overrides.
  • After an error, inspect status and observations before another write. A missing response does not prove that the request was ignored.

Test appearance separately

game.signals.showTexture(id, catalogue, image, durationMillis) temporarily replaces the image for 1 to 60 seconds; restoreTexture removes that replacement. Catalogue and image must identify valid resources. This affects display only: it forces neither logical aspect, permission nor braking.