OK, I'm still a little hazy on what you're trying to do, but I think I understand it.
If I'm right you want a SugarCube macro like this in your JavaScript section:
Macro.add("a", {
tags : null,
handler : function () {
if (State.temporary.articleStatus === undefined) {
// make sure that _articleStatus is initialized
State.temporary.articleStatus = {};
}
var articleStatus = State.temporary.articleStatus;
var txt = this.payload[0].contents;
var noun = txt.toLowerCase();
if (this.args.length > 0) {
// handle parameters
var count = this.args[0];
if (typeof count === 'number') {
if (articleStatus[ noun ] === undefined) {
articleStatus[ noun ] = {};
}
articleStatus[ noun ].count = count;
if (this.args[1] === undefined) {
articleStatus[ noun ].initial = "a";
} else {
articleStatus[ noun ].initial = this.payload[0].args[1];
}
if (this.args[2] === undefined) {
articleStatus[ noun ].secondary = "the";
} else {
articleStatus[ noun ].secondary = this.payload[0].args[2];
}
} else {
throw new Error("First parameter of 'a' macro must be either a number or undefined.");
}
}
var article;
if (hasOwnProperty.call(articleStatus, noun)) {
// noun exists, so set article appropriately
if (articleStatus[ noun ].count > 0) {
article = articleStatus[ noun ].initial;
--articleStatus[ noun ].count;
} else {
article = articleStatus[ noun ].secondary;
}
} else {
// default article
article = "a";
}
if (txt.charAt(0) === txt.charAt(0).toUpperCase()) {
// swap upperase from noun to article
article = article.charAt(0).toUpperCase() + article.slice(1);
txt = txt.charAt(0).toLowerCase() + txt.slice(1);
}
// output noun with appropriate article in front of it
$(this.output).wiki(article + " " + txt);
}
});
So if you used the above with this in a Twine passage:
<<a 3>>dude<</a>> - <<a 2 "an" "this">>orange<</a>>
<<a>>dude<</a>> - <<a>>orange<</a>>
<<a>>dude<</a>> - <<a>>Orange<</a>>
<<a>>Dude<</a>> - <<a>>dude<</a>>
<<a>>orange<</a>> - <<a>>Dude<</a>>
It would output this:
a dude - an orange
a dude - an orange
a dude - This orange
The dude - the dude
this orange - The dude
So, basically that "a" macro up top works like this:
<<a [count] [initialArticle = "a"] [secondaryArticle = "the"]>>noun<</a>>
The parameters in brackets are optional, and only need to be included the first time for each noun it's used on in a passage. If there is a "count" parameter, then that parameter must be a number. If the other two parameters are not included, "initialArticle" will be set to "a", and "secondaryArticle" will be set to "the". It then stores the noun in a temporary object ("_articleStatus"), along with the count, initialArticle, and secondaryArticle.
Then, if "count" > 0 for that noun, it will display the value of initialArticle followed by the noun and decrement count, otherwise it will put secondaryArticle before the noun (if the noun was capitalized, then the article will become capitalized instead). If that noun was never initialized with any parameters, then it defaults to putting the article "a" in front of the noun.
It will automatically keep track of each noun separately, so you can mix them together, as I showed above.
If you would like that information to work across passages then you could change "State.temporary" to "State.variables" (which makes it use "$articleStatus" instead), though keep in mind that the information will now take up space in your game's history.
If that wasn't what you were looking for, I'll need a bit clearer example of what you were trying to do, since I wasn't quite sure how it works the subsequent times you call to your <<article>> widget.
Also, I'm not the developer of SugarCube. That would be TheMadExile, so all thanks go to him for it.
In any case, I hope that helps!
P.S. You can change the name of that macro if you want to. I just called it "a" since you already had a widget called "article", "a" was shorter, and "a" is the default article that it prefaces things with. That said, if you do keep it, make sure you don't confuse the <<a>> macro with the <a> HTML element.
P.P.S. I've made multiple edits to the above over the last 20 minutes, so if you didn't see this P.P.S. before, please re-read the above.