0 votes
by (8.9k points)

Merry Boxing Day everybody!

So I'd like to generate a set of related traits for my NPCs.  Here's how I'm doing it right now:

<<set $npc to {}>>

<<set _jobRoll to random (1, 4)>>

<<if _jobRoll == 1>>
  <<set $npc.job to "rat catcher",
        $npc.socialClass to "low",
        $npc.equipment to "rat trap">>

  <<elseif _jobRoll == 2>>
  <<set $npc.job to "witch finder",
        $npc.socialClass to "medium",
        $npc.equipment to "pointy hat">>

  <<elseif _jobRoll == 3>>
  <<set $npc.job to "peasant",
        $npc.socialClass to "low",
        $npc.equipment to "mud">>

  <<elseif _jobRoll == 4>>
  <<set $npc.job to "priest",
        $npc.socialClass to "high",
        $npc.equipment to "holy book">>
<</if>>

This works, but I feel like I'm doing it inefficiently.  Is there a way to do this without the _jobRoll bit?  What I'd like to do is something like:

<<set $npc to {}>>

<<set setup.jobs to [
  Job title: 'Rat catcher' Social class: 'low' Equipment: "rat trap",
  Job title: 'Witch finder' Social class: 'medium' Equipment: "pointy hat"]>>

<<set $npc.job to setup.jobs.random()>>

Is that possible?

2 Answers

+1 vote
by (159k points)
selected by
 
Best answer

Is that possible?

Yes, if you define each element of your setup.jobs Array as a Generic Object.

<<set $npc to {}>>

<<set setup.jobs to [
  {"Job title": 'Rat catcher', "Social class": 'low', "Equipment": "rat trap"},
  {"Job title": 'Witch finder', "Social class": 'medium', "Equipment": "pointy hat"}
]>>

<<set $npc.job to setup.jobs.random()>>

Job title: <<= $npc.job["Job title"]>>
Social class: <<= $npc.job["Social class"]>>
Equipment: <<= $npc.job["Equipment"]>>

 

by (8.9k points)
Perfect, thank you Greyelf.
+1 vote
by (2.2k points)

You probably want to take a look at Improv, which is procedural text generator based on world model. There was even dedicated SugarCube plugin somewhere IIRC.

by (8.9k points)
Very interesting!  Thanks, NK.
...