I've wanted to make a dice roll/card draw generator for the journaling game Alone Among the Stars but I haven't figured out how to get the scripting to work, are these any examples of similar decks that anyone has made for me to look at?
The Koboldly Go! deck might be looking at. It rolls up randomized kobold NPCs for an adventure game. For each characteristic, there is an invisible grid widget containing a table of options, and the main card script picks a random row. The meat of the thing looks something like this:
on generate do gender .text:random[genders .value.value] eyecolor .text:random[eyecolors .value.value] skincolor.text:random[skincolors.value.value] voice .text:random[voices .value.value] mark .text:random[marks .value.value] friend .text:random[friends .value.value] bonus .text:"\n" fuse random[bonuses.value.value -2] quirk .text:"\n" fuse random[quirks .value.value -2] item .text:"\n" fuse random[items .value.value -2] end
For eye colors, we retrieve a random element from a column in the table stored in a grid widget "eyecolors" and store it in the text content of the field "eyecolor".
eyecolor.text:random[eyecolors.value.value]
Breaking it down,
For inventory items, we use a slightly different approach to pick two items without replacement (that is, two distinct items) and display each on its own line:
item.text:"\n" fuse random[items.value.value -2]
Breaking it down,
When you're only dealing with a handful of options, it might be even easier to skip the grid, and use a list of strings directly, like so:
on click do result.text:random[ "it is arduous to get to.", "you come upon it suddenly.", "you spot it as you are resting." ] end
Does that help clarify things at all?
Depending on how "automated" you want your adaptation to be, you might be able to use the die-roller contraption included in the Guided Tour deck; it doesn't require any scripting to use, just a D&D-style "dice notation" formula like "1d4+2" or "2d10+3d6":
For convenience, the contraption definition is here- it can be copied to your clipboard and pasted directly into a deck:
%%WGT0{"w":[{"name":"roller","type":"contraption","size":[137,23],"pos":[118,101],"def":"dieRoller","widgets":{"result":{"value":"1+5 = 6"},"button":{},"formula":{}}}],"d":{"dieRoller":{"name":"dieRoller","size":[137,23],"resizable":1,"margin":[90,8,8,9],"description":"roll dice using \"1d6+5\" notation.","script":"on roll x do\n r:() i:0\n x:\"\" fuse \" \" split x\n while (count x)>i\n if x[i]=\"+\"\n i:i+1\n else\n p:\"%[n]id%[die]i%[match]m%[i]n\" parse i drop x\n r:r,if p.match 1+random[p.die p.n] else p.n end\n i:i+p.i\n end\n end\n r\nend\n\non view do button.text:formula.text end\non set_formula x do formula.text:x view[] end\non get_formula do formula.text end","attributes":{"name":["formula"],"label":["Formula"],"type":["string"]},"widgets":{"result":{"type":"field","size":[51,19],"pos":[84,2],"style":"plain"},"button":{"type":"button","size":[79,19],"pos":[2,2],"script":"on click do\n v:roll[me.text]\n result.text:if 1=count v\n v\n else\n v:\"%s = %s\" format (\"+\" fuse v),(sum v)\n end\nend","text":"2d6","style":"rect"},"formula":{"type":"field","size":[33,20],"pos":[-8,-29],"locked":1,"show":"none","style":"plain","value":"2d6"}}}}}
The text representation shown above is just for clipboard interchange purposes; it isn't really intended for editing by hand.
If you want to view/edit the scripts comprising a contraption, open its Prototype by either choosing "Prototype..." from the properties panel of an instance of the contraption or choosing "File -> Prototypes...", selecting the prototype, and clicking "Edit...". While in the Prototype editor you can then choose "Prototype -> Script..." to view the main script.
For additional information, see the custom widgets tutorial.