Log inGet started
World

Procgen Effects Showcase

Branchmain
Branchesmain
Commit99ff90d12c

README.md

BenchRegenerator

BenchRegenerator keeps a generator re-cooking the way a game that edits its world does. Every every seconds it sets the graph input named input on the Generator of the entity named target, stepping through values and starting over at the end. A value the generator has not held before is a new cook.

The bench_mixed scene uses it twice. BenchRocksReroll re-rolls the rock field on BenchRocks (input = "seed", values = { 1 }, every = 2, stepping = true), and BenchValleyEdit edits the valley on BenchValley (input = "cut", values = { -60 }, every = 5, stepping = true). With stepping on, each of these counts up from its single value, so every re-cook is a new cook.

It looks up the target by name and reads that entity's Generator component.

Fields

FieldTypeDefaultDescription
targetstring""The name of the entity whose Generator is re-cooked.
inputstring"seed"The graph input set on each re-cook.
valuestable{ 1, 2, 3, 4 }The values the input steps through, in order, starting over at the end.
everynumber2Seconds between re-cooks.
steppingboolfalseCounts up from the last value once values is used up, so no value repeats and every re-cook is a cook the generator has not made before.

All fields are Sync.

Lifecycle

  • update(dt): while every is above 0, it adds dt to a timer. Each time the timer passes every, it finds the first entity named target, copies its Generator's params, sets params[input] to the next value and assigns the copy back to the Generator's params.

The next value is the next entry of values. Past the last entry, with stepping on and a numeric last entry, it is the last entry plus the number of steps taken past it; otherwise the sequence starts again at the first entry.

Usage

local reroll = entity.spawn("BenchRocksReroll")
reroll.component.add("BenchRegenerator", {
    target = "BenchRocks", input = "seed", values = { 1 }, every = 2, stepping = true,
})