- v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
- Use this page to report any issues related to the migration.
Difference between revisions of "Lua scripting"
(Initial announcement + info from follow up) |
m (Preformatted text) |
||
Line 10: | Line 10: | ||
==Code Samples== | ==Code Samples== | ||
+ | ===Divine language=== | ||
This is the [[divine language]], which generates a bunch of random-sounding words from a set of syllables. | This is the [[divine language]], which generates a bunch of random-sounding words from a set of syllables. | ||
− | + | <pre>languages.GEN_DIVINE=function() | |
local letters={} | local letters={} | ||
Line 65: | Line 66: | ||
return gen_divine | return gen_divine | ||
end | end | ||
− | + | </pre> | |
− | This makes a language called `GEN_IDENTITY` which is, like. "Abbey abbeyabbeys the abbey of abbeys" - i.e. it's the "English" language you might see occasionally. | + | ===Identity language=== |
− | + | This makes a language called ``GEN_IDENTITY`` which is, like. "Abbey abbeyabbeys the abbey of abbeys" - i.e. it's the "English" language you might see occasionally. | |
+ | |||
+ | <pre>languages.GEN_IDENTITY=function() | ||
-- just to demonstrate the absolute most basic method of generating one of these | -- just to demonstrate the absolute most basic method of generating one of these | ||
-- also so that you can just mod stuff to use GEN_IDENTITY | -- also so that you can just mod stuff to use GEN_IDENTITY | ||
Line 85: | Line 88: | ||
return tbl | return tbl | ||
end | end | ||
− | + | </pre> | |
[[Category:Modding]] | [[Category:Modding]] | ||
[[Category:Lua]] | [[Category:Lua]] |
Revision as of 03:54, 24 September 2024
Research Pending! This article or section is incomplete/under construction (likely due to recent changes) and may still be outdated or missing details. Feel free to do some testing and expand it. |
Modding |
---|
Tokens |
Audio · Biome · Graphics · Interaction · Mod info · Plant · Speech · Sphere · Syndrome · World |
Body tokens |
Body · Body detail plan · Bodygloss · Tissue |
Creature tokens |
Creature · Creature mannerism · Personality · Creature variation · Procedural graphics layer |
Descriptor tokens |
Descriptor color · Color · Descriptor pattern · Descriptor shape |
Entity tokens |
Entity · Ethic · Language · Value · Position |
Job tokens |
Building · Labor · Reaction · Skill · Unit type |
Item tokens |
Item type · Item definition · Ammo · Armor · Instrument · Tool · Trap component · Weapon |
Material tokens |
Material type · Material definition · Inorganic material definition |
This article is about procedural raw generation. Information on Utility:DFHack scripting can be found at https://docs.dfhack.org/en/stable/.
Lua scripting is an upcoming feature. It is used to create custom procedurally-generated objects that were previously created by hardcoded methods. It was announced in a video, with the stated goal of "supporting future magical endeavors."
Inorganic materials, languages, creatures, interactions, items (currently excluding instruments), reactions, entities, and plants are open to this system.
Code Samples
Divine language
This is the divine language, which generates a bunch of random-sounding words from a set of syllables.
languages.GEN_DIVINE=function() local letters={} letters.vowel={} letters.cons={} letters.vowel.COMMON_NUM=5 letters.vowel.NUM=35 letters.cons.COMMON_NUM=12 letters.cons.NUM=22 letters.vowel.lookup={ "a","e","i","o","u", "ae","ai","ao","au","ea","ei","eo","eu","ia","ie","io","iu","oa","oe","oi","ou","ua","ue","ui","uo","ah","eh","ih","oh","uh","ay","ey","iy","oy","uy" } letters.cons.lookup={ "b","p","g","k","c","z","s","d","t","m","n","ng", "v","f","w","h","j","l","r","q","x","y" } for k,v in pairs(letters) do v.common={} v.rare={} for i=1,5 do if trandom(5)~=0 then v.common[i]=v.lookup[trandom(v.COMMON_NUM)+1] else v.common[i]=v.lookup[trandom(v.NUM)+1] end end for i=1,15 do v.rare[i]=v.lookup[trandom(v.NUM)+1] end end local function letter(t) if trandom(5)~=0 then return pick_random(t.common) else return pick_random(t.rare) end end local gen_divine={} for k,v in ipairs(world.language.word) do local str="" if trandom(2)~=0 then str=str..letter(letters.cons) str=str..letter(letters.vowel) else str=str..letter(letters.vowel) end local num_letters=trandom(3) str=str..letter(letters.cons) if num_letters>0 then str=str..letter(letters.vowel) end if num_letters>1 then str=str..letter(letters.cons) end gen_divine[v.token]=str end return gen_divine end
Identity language
This makes a language called GEN_IDENTITY
which is, like. "Abbey abbeyabbeys the abbey of abbeys" - i.e. it's the "English" language you might see occasionally.
languages.GEN_IDENTITY=function() -- just to demonstrate the absolute most basic method of generating one of these -- also so that you can just mod stuff to use GEN_IDENTITY local tbl={} local unempty = function(str1, str2) return str1=='' and str2 or str1 end for k,v in ipairs(world.language.word) do local str='' str=unempty(str,v.NOUN_SING) str=unempty(str,v.ADJ) str=unempty(str,v.VERB_FIRST_PRES) str=unempty(str,string.lower(v.token)) tbl[v.token]=str end return tbl end