In looking for answers to this, I searched the site, and found the following post:
I'm trying to understand how to pass a variable back up to a calling generator. I've read through the documentation, and while it does show how to define variables, it does not cover how to reference variables or how to pass back variables. I've looked through the json files for NPC, and I believe I understand how things are moving, but I cannot replicate in my own generator, so I think I'm missing something.
In looking at NPC.json, we see the following bits:
Looking at the gender library, we see that they get initialized at the start of the library, and then assigned by calling the "common" gender table, and picking a gender which assigns the values using export command:
Back in the NPC.json, I see these variables referenced using a format of {g:varname}, such as this:
I believe what needs to happen is you define a global variable in your "master" generator, then define it again in your sub-generator/library, and set it via "export" in the sub-generator/library, so you can reference it using {g:varname} in your master... but it doesn't seem to work for me on the Generator Service test page.
What am I missing? Please help!
Helpful to have those links, but they were not really helpful in writing generators (many gaps, etc).Sure! Generators can call each other and they can pass values between them using global variables.
I'm trying to understand how to pass a variable back up to a calling generator. I've read through the documentation, and while it does show how to define variables, it does not cover how to reference variables or how to pass back variables. I've looked through the json files for NPC, and I believe I understand how things are moving, but I cannot replicate in my own generator, so I think I'm missing something.
In looking at NPC.json, we see the following bits:
And a little further down, we see code that inits some of these, and calls the gender library function, assigning gender, ambiguity, and orientation:"name": "NPC",
"resultPattern": "{init}{result}",
"globals": {
<snip>
"gender": "",
"ambiguity": "",
"orientation": "",
<snip>
"Subject": "",
"subject": "",
<snip>
"possessive": "",
"independentpossessive": "",
"reflexive": "",
The global variables Subject, subject, possessive, independentpossessive, and reflexive do not appear to be assigned anywhere in NPC.json."name": "init",
"explanation": "Initializing the required global variables, if any.",
"export": {
<snip>
"gender": "{lib:gender#common}",
"ambiguity": "{lib:gender#ambiguity}",
"orientation": "{lib:gender#orientation}",
Looking at the gender library, we see that they get initialized at the start of the library, and then assigned by calling the "common" gender table, and picking a gender which assigns the values using export command:
"name": "gender",
"resultPattern": "{init}{result}",
"globals": {
"gender": "",
"ambiguity": "",
"orientation": "",
"Subject": "",
"subject": "",
"object": "",
"possessive": "",
"independentpossessive": "",
"reflexive": ""
<big snip>
{
"name": "female",
"explanation": "Female gender.",
"export": {
"gender": "female",
"a gender": "a female",
"Subject": "She",
"subject": "she",
"object": "her",
"possessive": "her",
"independentpossessive": "hers",
"reflexive": "herself"
}
Back in the NPC.json, I see these variables referenced using a format of {g:varname}, such as this:
note: I added a space after lib: so that this post won't turn it into a smily"{g:Subject} is wearing {lib: outfit}"
I believe what needs to happen is you define a global variable in your "master" generator, then define it again in your sub-generator/library, and set it via "export" in the sub-generator/library, so you can reference it using {g:varname} in your master... but it doesn't seem to work for me on the Generator Service test page.
What am I missing? Please help!