en:guide:improv

Using Improv

Improv (source code, documentation) is a powerful procedural generation engine by Bruno Dias.

While the questions of why you might need Improv and how to use it are sorta out of the scope for this document, there is an important details on how to use it with Salet.

You see, since November 2016 Improv allows to use a custom RNG (random number generator). If you hook it up with Salet's RNG (conveniently exposed as salet.rnd) it will return the same text every time the player loads the game. If you don't, however, it will return different text every time.

Long story short, here's minimal code:

Improv = new ImprovEngine(data, {
  rng: () ->
    return salet.rnd.randf()
})

and a real example:

require('babel-polyfill')
ImprovEngine = require('improv')
Improv = {}

$.holdReady( true )
$.getJSON('game/procgen/'+i18n.lang+'.json', (data) ->
  Improv = new ImprovEngine(data, {
    rng: () ->
      return salet.rnd.randf()
    filters: [
      ImprovEngine.filters.mismatchFilter()
    ]
    reincorporate: false
  })

  $.holdReady( false )
)

where:

  • babel-polyfill is needed for browser compatibility; Improv is written in ES6, it doesn't work in older browsers as it is
  • holdReady bit loads procgen data with an AJAX request and forbids the game to start until the request is finished.

and the rest is explained in Improv documentation.

  • en/guide/improv.txt
  • Last modified: 2021/01/24 10:42
  • by 127.0.0.1