Your browser lacks required capabilities. Please upgrade it or switch to another to continue.
Loading…
There are many different ways to approach procedural generation of content in Twine. This example covers using passages (as storage) and widgets as a method to generate content.
This example uses the SugarCube 2.21.0 story format.
This is based on the Lesser Key of Solomon (__Clavicula Salomonis Regis__)
Example: <blockquote>BAEL- The First Principal Spirit is a King ruling in the East, called Bael. He maketh thee to go Invisible. He ruleth over 66 Legions of Infernal Spirits. He appeareth in diverse shapes, sometimes like a Cat, sometimes like a Toad, and sometimes like a Man, and sometimes all these forms at once. He speaketh hoarsely. This is his character which is used to be worn as a Lamen before him who calleth him forth, or else he will not do thee homage.</blockquote>
<<nobr>>
<<for _i to 0; _i < 78; _i++>>
<<getspiritname>>
<<gettool>>
<<getanimal>>
<<getadjectives>>
<<gettalents>>
''(<<print _i + 1>>)'': The spirit $randomSpiritName is a <<print either("Great", "Minor")>> <<print either("King", "Marquis", "Duke", "Prince", "President")>>, appears as $animal, and carries $tool. He $talents. He is found within $adjectives <<print $tag + "s">>. He rules over <<print random(20,600)>> legions of spirits.
<</for>>
<</nobr>><<widget "getspiritname">>
<<silently>>
<<set _passageContents to Story.get("Spirit Names")>>
<<set _passageText to _passageContents.text>>
<<set _splitContents to _passageText.split("\n")>>
<<set _randomSyllables to random(0,3)>>
<<set $randomSpiritName to _splitContents.pluck()>>
<<for _k to 0; _k < _randomSyllables; _k++>>
<<set _randomNumber to random(0, _splitContents.length-1)>>
<<set $randomSpiritName to $randomSpiritName + _splitContents.pluck()>>
<</for>>
<<set $randomSpiritName to $randomSpiritName.replace(/^\w/, c => c.toUpperCase())>>
<</silently>>
<</widget>>ba
el
aga
res
vas
sago
sami
gina
mar
bas
vale
for
am
on
barb
atos
pai
mon
bu
er
gus
ion
si
tri
bel
eth
ler
aje
eli
gos
ze
par
bot
is
bat
hin
sal
los
pur
son
mar
ax
ip
os
a
im
naber
ius
gla
sya
labo
las
ron
ove
ber
ith
asta
roth
for
neus
fo
ras
asmo
day
ga
ap
fur
fur
mar
cho
sias
sto
las
phen
ex
hal
phas
mal
phas
ra
um
foc
alor
ve
par
sab
nock
sh
ax
vi
ne
bi
frons
vu
al
haa
genti
croc
ell
fur
cas
bal
am
all
oces
ca
im
mur
oro
bas
gre
mory
o
se
a
my
or
ias
va
pula
za
gan
va
lac
an
dras
fla
uros
an
dreal
phus
ki
maris
amd
usias
be
lial
dec
ara
bia
se
ere
dan
ta
lion
andr
oma
liusan axe
a basket
cloth shears
a crowbar
a hammer
a handsaw
tongs
a mallet
a chisel
a pitch fork
a blade
shears
a sickle
a trowelan antelope,forest
a gazelle,desert
a deer,forest
a gerbil,forest
a panda,forest
a giraffe,desert
a warthog,forest
an elephant,desert
a pig,forest
an ocelot,forest
a tiger,desert
a hyena,forest
a coyote,forest
a mongoose,forest
a cheetah,desert
a lion,desert
a leopard,desert
a fox,forest
a jackal,forest
a badger,forest
a jaguar,forest
an armadillo,forest
an alpaca,forest
an anteater,forest
an otter,forest
a ferret,plain
a bobcast,plain
an owl,plain
a spider,plain
a goose,plain<<widget "gettool">>
<<silently>>
<<set _passageContents to Story.get("Tools")>>
<<set _passageText to _passageContents.text>>
<<set _splitContents to _passageText.split("\n")>>
<<set _randomTool to _splitContents[random(0, _splitContents.length-1)]>>
<<set $tool to _randomTool>>
<</silently>>
<</widget>><<widget "getanimal">>
<<silently>>
<<set _passageContents to Story.get("Animals")>>
<<set _passageText to _passageContents.text>>
<<set _splitContents to _passageText.split("\n")>>
<<set _line to _splitContents[random(0, _splitContents.length-1)]>>
<<set _splitLine to _line.split("\,")>>
<<set _randomAnimal to _splitLine[0]>>
<<set $tag to _splitLine[1]>>
<<set $animal to _randomAnimal>>
<</silently>>
<</widget>>reveals hidden or secret things
causes and heals diseases
teaches medical arts
changes men into other shapes
tempts people to steal
grants a good relationship among thieves
reconciles friends and foes
procures love for those seeking it
understands all things of the past
understands all things of the future
speaks to animals
leads men to treasure hidden by the enchantment of magicians
locates lost objects
teaches science and answering other questions
teaches natural and moral philosophy
teaches virtues of all herbs and plants
heals all infirmities
bestows good familiars
brings abundance
causes great battles and disputes
makes gangrene wounds caused by arrows
knows how soldiers should meet
attracts the favor of lords, knights and other important persons
causes women to love men
causes men to love women
causes men to love men
causes women to love women
makes women barren
knows the virtues of precious stones and herbs
brings men suddenly from one country to another
grants astral projection
knows of hidden things
makes men cunning in all arts
restores lost dignities and honors
teaches the art of gracious living
knows all sciences
incites homicides
takes old souls
takes young souls
causes men to have a good name
causes women to have a good name
gives the knowledge and understanding of tongues<<widget "gettalents">>
<<silently>>
<<set _passageContents to Story.get("Talents")>>
<<set _passageText to _passageContents.text>>
<<set _splitContents to _passageText.split("\n")>>
<<set $talents to _splitContents.pluck() + ", " + _splitContents.pluck() + ", and " + _splitContents.pluck()>>
<</silently>>
<</widget>>great
fertile
open
vast
high
grassy
wide
flat
broad
extensive
sandy
rich
dry
low
arid
treeless
barren
abyssal
immense
hot
green
endless
dusty
beautiful
smooth
desolate
bare
distant
empty
verdant
dreary
bleak
sterile
frozen
volcanicdense
thick
natural
vast
extensive
dark
primeval
deep
dry
moist
ancient
open
green
immense
impenetrable
rich
wet
wild
humid
lush
beautiful
heavy
gloomy
huge
tall
endless
distant
remote
mighty
tangledgreat
sandy
vast
barren
arid
high
semi
open
hot
dry
ill
empty
flat
dreary
moral
cold
stony
wide
trackless
rocky
endless
wild
lonely
inhospitable
red
immense
bleak
boundless
dark
bare
sterile
silent
polar
dusty
harsh
terrible
lifeless
yellow
pathless
thirsty
frightful
gray
huge<<widget "getadjectives">>
<<silently>>
<<set _passageContents to Story.get($tag)>>
<<set _passageText to _passageContents.text>>
<<set _splitContents to _passageText.split("\n")>>
<<set _randomAdjectives to _splitContents.pluck() + ", " + _splitContents.pluck()>>
<<set $adjectives to _randomAdjectives>>
<</silently>>
<</widget>>