Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Make Your Own Chicken Generator!

A topic by Internet Janitor created 45 days ago Views: 133
Viewing posts 1 to 1
Developer(+2)

Many pen-and-paper games, including RPGs, journaling games, and card games make use of random numbers and lookup tables to control outcomes. I thought it might be useful to detail the construction of a table-driven character generator to demonstrate how Decker can be used to make semi-automated play aids for such games. I'll make a random chicken generator, but I encourage you to take a stab at creating your own variation with a theme that appeals to you creatively.

This tutorial is written with Decker v1.41 in mind, so if you're on an older release make sure you upgrade before following along.

Names

The simplest way of using random lookup tables is choosing a single item from a list. We'll start by creating three widgets:

  • A grid which will contain our list of chicken names, called "names". This grid will contain a single column called "value". For the purposes of this example I have borrowed a list of 100 proposed chicken names found here. Note how I fill the grid with data by choosing "edit as CSV" (Comma-Separated Value). The first line of the CSV specifies the column name, and all subsequent lines are data.
  • A field which will contain one randomly chosen chicken name, called "name".
  • A button which will tell decker to choose a chicken name, titled "Generate".

Fill in the script for the button like so:

on click do
 name.text: random[names.value].value
end

Step by step,


Try clicking "Generate" a few times!


We could make a variety of additional random character traits by following the same pattern: make another grid with a column of options, fill it in appropriately, make a field to contain a result, and write a button script to make the selection. You can modify the contents of the grid to change the set of available options, and if you want certain options to be more common you can put your thumb on the scale by making multiple copies of some rows. If you don't want the user to see all the options up-front, you could hide the grid (Widgets -> Show None). You could also choose to generate multiple attributes from the same button script or divide them up to permit users to re-roll each individually.

Note that if you're editing grids in CSV mode, it is essential that any data rows containing commas be enclosed in double-quotes. If you prefer, you can compose large tables in a spreadsheet program like Excel, export as CSV, and either copy and paste them into the grid properties panel or select the grid in Interact mode and choose File -> Import Table...

Multiple Choice

Another variation on random selection that may be useful is selecting two or more values from a table, and ensuring for the sake of variety that they're distinct. Let's give our chicken two favorite foods from a table of chicken delicacies. First, an extra field and grid (along with some extra fields for labels):


Then I'll add my secret sauce to the "Generate" button's script:

on click do
 name.text: random[names.value].value
 food.text: "\n" fuse random[foods.value -2]..value
end

The main trick here is that by specifying a negative number as the second argument to the random[] function we will get random items without replacement; that is, distinct items. -3 would generate three distinct items, and so on, up to the size of the table. Since random[] will now return a list of dictionaries (each a row of the table), we can use the ".." syntax to obtain the "value" field from each dictionary, and intercalate newlines ("\n") between each food with "fuse".

A different (but equivalent) way of solving the problem would be to first peel the "value" column out of the grid's table and then choose two random items from the resulting list:

food.text: "\n" fuse random[foods.value.value -2]

Descriptions

In some cases, you may wish to glue together several choices to produce a coherent prose description. For example, we might wish to have a paragraph like:

She is a small pullet with red feathers.

The pronoun "She" needs to be selected along with "pullet" (a juvenile female hen) to make sense, so we'll have a grid with two columns, "type" and "pronoun", that are correlated appropriately. In CSV:

type,pronoun
chick,She
chick,He
pullet,She
cockerel,He
hen,She
rooster,He

Our widgets:

Since sizes and feather colors can be short lists, we'll demonstrate two different ways their options can be defined directly within our script.

Here's the new button script in its entirety. Generating the description is much more complicated than the previous two lines, but it contains many things we've seen before:

colors:insert value with
  "red"
  "brown"
  "white"
  "gray"
  "black"
end
on click do
 name.text: random[names.value].value
 food.text: "\n" fuse random[foods.value.value -2]
 d:random[types.value]
 d.size:random["bantam","small","medium-sized","large","colossal"]
 d.color:random[colors].value
 des.text:"%[pronoun]s is a %[size]s %[type]s with %[color]s feathers." format d
end

Step by step,


And the final chicken generator in action:


I hope this writeup starts some ideas fermenting in the minds of Decker users. Feel free to ask followup questions, and if you build your own thing-generator I'd love to see it!