-
Below is my code for a prompt that will give basic information about an NPC for a Walking Dead game, what I'm trying to do is insert a name into text based on the result of a gender prompt ("guy", "lady", "someone"). I've got three notes 'mfname' (male first names), 'ffname' (female first names), and 'lname' (last names). I'm assuming this is a simple if/then statement, but how could I get it to output a name for this character along with the rest of the prompt so that it says something like, "Their name is ...." after it spits out all that other text. It would ideally match up gender with the lists, so something like 'If gender = "guy" then ${mfname} ${lname}', I'm just not familiar enough with the JS to understand how to do that. Does anybody know how I can accomplish that? This script generates prompts from files containing lists of prompts async function readFile(folderName, fileName) {
let filePath = folderName + fileName + '.md';
let file = this.app.vault.getAbstractFileByPath(filePath);
if(!file) {
return "No such file" + filePath
}
let content = await this.app.vault.read(file)
return content
}
function randomPrompt(content) {
let prompts = content.split("\n")
var randomPrompt = prompts[Math.floor(Math.random()*prompts.length)];
return randomPrompt
}
function roll(max)
{
return Math.trunc(Math.random() * max + 1);
}
async function generatePrompt(fileName) {
let folderName = "assets/prompts/"
const content = await readFile(folderName, fileName)
const prompt = randomPrompt(content)
return prompt.toLowerCase()
}
const age = await generatePrompt("ages")
const gender = await generatePrompt("genders")
const occupation = await generatePrompt("occupations")
const party = await generatePrompt("parties")
const appearance = await generatePrompt("appearances")
const flaw = await generatePrompt("flaws")
const demeanor = await generatePrompt("demeanors")
const motivation = await generatePrompt("motivations")
const attitude = await generatePrompt("attitudes")
const topic = await generatePrompt("topics")
const action = await generatePrompt("actions")
const mfname = await generatePrompt("mfnames")
const ffname = await generatePrompt("ffnames")
const lname = await generatePrompt("lnames")
const allPrompts =`
You meet ${age} ${gender} who used to work as ${occupation}, they're traveling ${party}. They look to be ${appearance}, but also seem to be ${flaw} and ${demeanor} towards you. They seem to be primarily motivated to ${motivation} and feel ${attitude} about ${topic}. They're currently ${action}.
`
return allPrompts __ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
So I was able to cobble together the following to get if/then statements in the way I needed it. There's probably a better way to do it, but it's how I figured out how to get it done:
|
Beta Was this translation helpful? Give feedback.
So I was able to cobble together the following to get if/then statements in the way I needed it. There's probably a better way to do it, but it's how I figured out how to get it done: