galaxykate / tracery

Tracery: a story-grammar generation library for javascript
Apache License 2.0
2.11k stars 246 forks source link

Process modifiers before deactivating actions? #7

Open yanamal opened 8 years ago

yanamal commented 8 years ago

I think it would make more sense to process modifier functions while the actions (on that same symbol/keyword) are still active, and so the symbols introduced in the actions are still "in scope", so to speak.

Granted, I am sort of using this system for things it was never intended for. I wrote some custom modifiers that produce side effects in other data structures, and I'm trying to sneak more information to these custom functions via actions.

dranorter commented 7 years ago

It turns out this is an easy fix. I wanted to make a ".eval" modifier so I needed the "this" keyword inside the modifier to expose the grammar as it stood at time of application. I think this is the same thing you mean. I don't know what version of Tracery you (were/are) using, but using the NPM version 2.7.3, you will find there is a line

this.finishedText = mod(this.finishedText, modParams);

which you should change to

this.finishedText = mod.call(this, this.finishedText, modParams);

If you're still around or even still remember what this was about, @yanamal , I'd be curious to know what you were doing.

@galaxykate Could this be included in the NPM code?

yanamal commented 7 years ago

I can't remember what exactly I was trying to do anymore, sorry. I believe this is what I was working on, though: http://yanamal.pencilcode.net/edit/storygen/grammar2

(note: yes, this is actually real html/javascript. there are little yellow taps you can click on to make the block formatting go away).

So definitely not NPM - but if I take it up again, I'll keep it in mind, thanks!

dranorter commented 7 years ago

Oh, sorry if that last sentence was misleading, I was trying to ping GalaxyKate and see if she thought the one-line change ought to be in the Tracery NPM.